diff --git a/CHANGELOG.md b/CHANGELOG.md index 09db1414..b1403414 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,10 @@ ## 6.4.0 Expected: October 2023 +### Minor features + +* Clarified clixon_cli command-line: `clixon_cli [options] [commands] [-- extra-options]` + ## 6.3.0 29 July 2023 diff --git a/apps/cli/cli_main.c b/apps/cli/cli_main.c index b4293ae6..ac230ceb 100644 --- a/apps/cli/cli_main.c +++ b/apps/cli/cli_main.c @@ -414,14 +414,63 @@ autocli_start(clicon_handle h) return retval; } +/*! Split remaining argv/argc into [commands] and [-- ] + * + * CLI command-line is: [options] [commands] [-- extra-options]" + * The special argument "--" forces an end of option-scanning regardless of the scanning mode. + * For example: clixon_cli -f /etc/clixon.xml show config -- -m clixon-mount + * @þaram[in] h Clixon handle + * @þaram[in] argc Input commands after + * @þaram[in] argv Input commands after + * @þaram[in] argv0 First command + * @þaram[out] restcmd Commands + * @retval 0 OK + * @retval -1 Error + */ +static int +options_split(clicon_handle h, + char *argv0, + int argc, + char **argv, + char **restcmd) +{ + int retval = -1; + int i; + int j; + + /* Join rest of argv to a single command (but only up to -- ) */ + for (i = 0; i < argc; i++){ + if (strcmp(argv[i], "--") == 0) + break; + } + if (i < argc){ /* '--' delimiter found */ + *restcmd = clicon_strjoin(i, argv, " "); + for (j=0; j \tDebug level\n" @@ -632,15 +681,16 @@ main(int argc, argv += optind; #ifdef __AFL_HAVE_MANUAL_CONTROL - __AFL_INIT(); + __AFL_INIT(); #endif - /* Access the remaining argv/argc options (after --) w clicon-argv_get() */ - clicon_argv_set(h, argv0, argc, argv); - /* Defer: Wait to the last minute to print help message */ if (help) usage(h, argv[0]); + + /* Split remaining argv/argc into and */ + if (options_split(h, argv0, argc, argv, &restarg) < 0) + goto done; /* Init cligen buffers */ cligen_buflen = clicon_option_int(h, "CLICON_CLI_BUF_START"); @@ -785,8 +835,7 @@ main(int argc, clicon_option_dump(h, 1); - /* Join rest of argv to a single command */ - restarg = clicon_strjoin(argc, argv, " "); + /* Clixon hardcodes variable tie-breaks to non-terminals (2) * There are cases in the autocli such as: @@ -814,8 +863,9 @@ main(int argc, */ clicon_data_set(h, "session-transport", "cl:cli"); - /* Launch interfactive event loop, unless -1 */ - if (restarg != NULL && strlen(restarg)){ + /* Launch interfactive event loop, + * unless options, in which case they are catched by clicon_argv_get/set */ + if (restarg != NULL && strlen(restarg) && restarg[0] != '-'){ char *mode = cli_syntax_mode(h); cligen_result result; /* match result */ int evalresult = 0; /* if result == 1, calback result */ diff --git a/apps/cli/cli_show.c b/apps/cli/cli_show.c index 47abea60..ade8fa1d 100644 --- a/apps/cli/cli_show.c +++ b/apps/cli/cli_show.c @@ -858,11 +858,15 @@ done: return retval; } -int cli_show_version(clicon_handle h, - cvec *vars, - cvec *argv) +/*! Show clixon and CLIgen versions + */ +int +cli_show_version(clicon_handle h, + cvec *vars, + cvec *argv) { - fprintf(stdout, "%s\n", CLIXON_VERSION_STRING); + fprintf(stdout, "Clixon: %s\n", CLIXON_VERSION_STRING); + fprintf(stdout, "CLIgen: %s\n", CLIGEN_VERSION); return 0; } diff --git a/apps/cli/clixon_cli_api.h b/apps/cli/clixon_cli_api.h index 5db08135..d650a67e 100644 --- a/apps/cli/clixon_cli_api.h +++ b/apps/cli/clixon_cli_api.h @@ -133,6 +133,7 @@ int cli_show_config_state(clicon_handle h, cvec *cvv, cvec *argv); int cli_show_auto(clicon_handle h, cvec *cvv, cvec *argv); int cli_show_options(clicon_handle h, cvec *cvv, cvec *argv); +int cli_show_version(clicon_handle h, cvec *vars, cvec *argv); /* cli_auto.c: Autocli mode support */