diff options
author | Harald Welte <laforge@osmocom.org> | 2021-02-23 17:15:35 +0100 |
---|---|---|
committer | Harald Welte <laforge@osmocom.org> | 2021-02-23 17:20:08 +0100 |
commit | 6d8d9b3ced72d4fe8307e90d4baedd6cf3a5e05a (patch) | |
tree | c3249d2ed40edf36795c0384a9220df2a2fbbac9 | |
parent | 7eedb6b03c6615035b2601d720fd2b10d9d513aa (diff) |
main: add --vty-ref-mode, use vty_dump_xml_ref_mode()
Change-Id: Ia5abf7457ee7e97ec3fcd5520e5ef82ef808667a
Related: OS#5041
Depends: Ie2022a7f9e167e5ceacf15350c037dd43768ff40
-rw-r--r-- | stp/stp_main.c | 45 |
1 files changed, 40 insertions, 5 deletions
diff --git a/stp/stp_main.c b/stp/stp_main.c index 42f7108..c7a6272 100644 --- a/stp/stp_main.c +++ b/stp/stp_main.c @@ -89,17 +89,49 @@ static void print_help(void) printf(" -D --daemonize Fork the process into a background daemon\n"); printf(" -c --config-file filename The config file to use. Default: ./osmo-stp.cfg\n"); printf(" -V --version Print the version of OsmoSTP\n"); + + printf("\nVTY reference generation:\n"); + printf(" --vty-ref-mode MODE VTY reference generation mode (e.g. 'expert').\n"); + printf(" --vty-ref-xml Generate the VTY reference XML output and exit.\n"); +} + +static void handle_long_options(const char *prog_name, const int long_option) +{ + static int vty_ref_mode = VTY_REF_GEN_MODE_DEFAULT; + + switch (long_option) { + case 1: + vty_ref_mode = get_string_value(vty_ref_gen_mode_names, optarg); + if (vty_ref_mode < 0) { + fprintf(stderr, "%s: Unknown VTY reference generation " + "mode '%s'\n", prog_name, optarg); + exit(2); + } + break; + case 2: + fprintf(stderr, "Generating the VTY reference in mode '%s' (%s)\n", + get_value_string(vty_ref_gen_mode_names, vty_ref_mode), + get_value_string(vty_ref_gen_mode_desc, vty_ref_mode)); + vty_dump_xml_ref_mode(stdout, (enum vty_ref_gen_mode) vty_ref_mode); + exit(0); + default: + fprintf(stderr, "%s: error parsing cmdline options\n", prog_name); + exit(2); + } } static void handle_options(int argc, char **argv) { while (1) { int option_index = 0, c; + static int long_option = 0; static const struct option long_options[] = { { "help", 0, 0, 'h' }, { "daemonize", 0, 0, 'D' }, { "config-file", 1, 0, 'c' }, { "version", 0, 0, 'V' }, + { "vty-ref-mode", 1, &long_option, 1 }, + { "vty-ref-xml", 0, &long_option, 2 }, { NULL, 0, 0, 0 } }; @@ -108,6 +140,9 @@ static void handle_options(int argc, char **argv) break; switch (c) { + case 0: + handle_long_options(argv[0], long_option); + break; case 'h': print_help(); exit(0); @@ -176,11 +211,6 @@ int main(int argc, char **argv) vty_info.tall_ctx = tall_stp_ctx; vty_init(&vty_info); - handle_options(argc, argv); - - fputs(stp_copyright, stdout); - fputs("\n", stdout); - OSMO_ASSERT(osmo_ss7_init() == 0); osmo_fsm_log_addr(false); logging_vty_add_cmds(); @@ -191,6 +221,11 @@ int main(int argc, char **argv) osmo_fsm_vty_add_cmds(); osmo_talloc_vty_add_cmds(); + handle_options(argc, argv); + + fputs(stp_copyright, stdout); + fputs("\n", stdout); + rc = vty_read_config_file(cmdline_config.config_file, NULL); if (rc < 0) { fprintf(stderr, "Failed to parse the config file '%s'\n", |