From e44ec43f55d57914fecc327681bf96e1feedf98c Mon Sep 17 00:00:00 2001 From: Dengda98 Date: Mon, 4 Aug 2025 12:33:04 +0800 Subject: [PATCH 1/2] FEAT: add `grt -v` to show the version --- pygrt/C_extension/src/grt.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/pygrt/C_extension/src/grt.c b/pygrt/C_extension/src/grt.c index 43e127a0..766819de 100644 --- a/pygrt/C_extension/src/grt.c +++ b/pygrt/C_extension/src/grt.c @@ -46,7 +46,14 @@ print_logo(); printf("\n" "Usage: \n" "----------------------------------------------------------------\n" -" grt [options] ...\n\n\n"); +" grt [options]\n" +" grt [] ...\n\n\n" +"Options:\n" +"----------------------------------------------------------------\n" +" -v Display version.\n" +"\n" +" -h Display this help message.\n" +); printf("GRT supports the following submodules:\n" "----------------------------------------------------------------\n"); for (MYINT n = 0; GRT_Submodule_Names[n] != NULL; ++n) { @@ -61,8 +68,14 @@ printf("For each submodule, you can use -h to see the help message.\n\n"); static void getopt_from_command(GRT_MAIN_CTRL *Ctrl, int argc, char **argv){ char* command = Ctrl->name; int opt; - while ((opt = getopt(argc, argv, ":h")) != -1) { + while ((opt = getopt(argc, argv, ":vh")) != -1) { switch (opt) { + // 打印版本 + case 'v': + printf(GRT_MAIN_COMMAND" %s\n", GRT_VERSION); + exit(EXIT_SUCCESS); + break; + GRT_Common_Options_in_Switch(command, optopt); } } From cfd485dbbcb6ab984b362bfb31ad8616284fc1be Mon Sep 17 00:00:00 2001 From: Dengda98 Date: Mon, 4 Aug 2025 12:36:50 +0800 Subject: [PATCH 2/2] adjust style --- pygrt/C_extension/src/grt.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pygrt/C_extension/src/grt.c b/pygrt/C_extension/src/grt.c index 766819de..4ab0a951 100644 --- a/pygrt/C_extension/src/grt.c +++ b/pygrt/C_extension/src/grt.c @@ -50,18 +50,20 @@ printf("\n" " grt [] ...\n\n\n" "Options:\n" "----------------------------------------------------------------\n" -" -v Display version.\n" +" -v Display the program version.\n" "\n" " -h Display this help message.\n" -); +"\n\n"); printf("GRT supports the following submodules:\n" "----------------------------------------------------------------\n"); for (MYINT n = 0; GRT_Submodule_Names[n] != NULL; ++n) { const char *name = GRT_Submodule_Names[n]; printf(" %-s\n", name); } -printf("\n\n"); -printf("For each submodule, you can use -h to see the help message.\n\n"); +printf("\n" +"For each submodule, you can use -h to see its help message, e.g.\n" +" grt greenfn -h \n" +"\n"); } /** 从命令行中读取选项,处理后记录到参数控制结构体 */