From c5a0ab6efdcff6e0bb5dbf2984c94399a14ea267 Mon Sep 17 00:00:00 2001 From: Vadim Yanitskiy Date: Fri, 23 Oct 2020 20:50:21 +0700 Subject: main: add --vty-ref-mode, use vty_dump_xml_ref_mode() Change-Id: I1a89829a29dd38fe69002c898503d76a3376a874 Depends: Ie2022a7f9e167e5ceacf15350c037dd43768ff40 Related: SYS#4910 --- src/osmo-bsc/osmo_bsc_main.c | 45 +++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/src/osmo-bsc/osmo_bsc_main.c b/src/osmo-bsc/osmo_bsc_main.c index 7eaa18ffd..aa45bf07f 100644 --- a/src/osmo-bsc/osmo_bsc_main.c +++ b/src/osmo-bsc/osmo_bsc_main.c @@ -96,7 +96,7 @@ static void print_usage() static void print_help() { - printf(" Some useful help...\n"); + printf("Some useful options:\n"); printf(" -h --help This text.\n"); printf(" -D --daemonize Fork the process into a background daemon.\n"); printf(" -d --debug option --debug=DRLL:DMM:DRR:DRSL:DNM enable debugging.\n"); @@ -108,7 +108,35 @@ static void print_help() printf(" -e --log-level number Set a global loglevel.\n"); printf(" -r --rf-ctl NAME A unix domain socket to listen for cmds.\n"); printf(" -t --testmode A special mode to provoke failures at the MSC.\n"); - printf(" --vty-ref-xml Generate the VTY reference XML output and exit.\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) @@ -128,7 +156,8 @@ static void handle_options(int argc, char **argv) {"log-level", 1, 0, 'e'}, {"rf-ctl", 1, 0, 'r'}, {"testmode", 0, 0, 't'}, - {"vty-ref-xml", 0, &long_option, 1}, + {"vty-ref-mode", 1, &long_option, 1}, + {"vty-ref-xml", 0, &long_option, 2}, {0, 0, 0, 0} }; @@ -143,14 +172,8 @@ static void handle_options(int argc, char **argv) print_help(); exit(0); case 0: - switch (long_option) { - case 1: - vty_dump_xml_ref(stdout); - exit(0); - default: - fprintf(stderr, "error parsing cmdline options\n"); - exit(2); - } + handle_long_options(argv[0], long_option); + break; case 's': log_set_use_color(osmo_stderr_target, 0); break; -- cgit v1.2.3