Feature: [Add support for -V option to give version](https://github.com/clicon/clixon/issues/472)

This commit is contained in:
Olof hagsand 2023-12-14 22:48:13 +01:00
parent 2f81a086c8
commit 261469be16
11 changed files with 209 additions and 42 deletions

View file

@ -73,8 +73,7 @@
#include "cli_handle.h"
/* Command line options to be passed to getopt(3) */
#define CLI_OPTS "+hD:f:E:l:C:F:1a:u:d:m:qp:GLy:c:U:o:"
#define CLI_OPTS "+hVD:f:E:l:C:F:1a:u:d:m:qp:GLy:c:U:o:"
/*! Check if there is a CLI history file and if so dump the CLI histiry to it
*
* Just log if file does not exist or is not readable
@ -481,6 +480,7 @@ usage(clicon_handle h,
"and extra-options are app-dependent and passed to the plugin init function\n"
"where options are\n"
"\t-h \t\tHelp\n"
"\t-V \t\tPrint version and exit\n"
"\t-D <level> \tDebug level\n"
"\t-f <file> \tConfig-file (mandatory)\n"
"\t-E <dir> \tExtra configuration file directory\n"
@ -532,8 +532,9 @@ main(int argc,
size_t cligen_bufthreshold;
int dbg=0;
int nr;
int config_dump;
int config_dump;
enum format_enum config_dump_format = FORMAT_XML;
int print_version = 0;
/* Defaults */
once = 0;
@ -574,6 +575,10 @@ main(int argc,
*/
help = 1;
break;
case 'V': /* version */
cligen_output(stdout, "Clixon version %s\n", CLIXON_VERSION_STRING);
print_version++; /* plugins may also print versions w ca-version callback */
break;
case 'D' : /* debug */
if (sscanf(optarg, "%d", &dbg) != 1)
usage(h, argv[0]);
@ -616,11 +621,12 @@ main(int argc,
while ((c = getopt(argc, argv, CLI_OPTS)) != -1){
switch (c) {
case 'D' : /* debug */
case 'f': /* config file */
case 'E': /* extra config dir */
case 'l': /* Log destination */
case 'V' : /* version */
case 'f' : /* config file */
case 'E' : /* extra config dir */
case 'l' : /* Log destination */
break; /* see above */
case 'C': /* Explicitly dump configuration */
case 'C' : /* Explicitly dump configuration */
if ((config_dump_format = format_str2int(optarg)) == (enum format_enum)-1){
fprintf(stderr, "Unrecognized dump format: %s(expected: xml|json|text)\n", argv[0]);
usage(h, argv[0]);
@ -766,7 +772,12 @@ main(int argc,
goto done;
}
#endif
/* Print version, customized variant must wait for plugins to load */
if (print_version){
if (clixon_plugin_version_all(h, stdout) < 0)
goto done;
exit(0);
}
/* Add (hardcoded) netconf features in case ietf-netconf loaded here
* Otherwise it is loaded in netconf_module_load below
*/