diff options
author | Thomas Haller <thaller@redhat.com> | 2013-11-11 14:57:25 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2013-11-11 15:27:45 +0100 |
commit | c9cfbae12bea267730e867ba1c1d54cd9d150046 (patch) | |
tree | 371c1b998c6d82d716c1ea5492f88334022041a2 | |
parent | 93131b1df2fc2246fed6004d76d3bbff4fcf60e8 (diff) | |
download | NetworkManager-c9cfbae12bea267730e867ba1c1d54cd9d150046.tar.gz |
cli: make command line parsing check for help option first
Move the checks for nmc_arg_is_help to the beginning of the
checks for command matches.
Up to now, no command begins with 'h', so this has no behavioral
change whatsoever. But imagine a command that begins with 'h'
(for example `nmcli general hostname`), in that case `nmcli general h`
should still show the help, as users might be accustomed to this
abbreviation.
Signed-off-by: Thomas Haller <thaller@redhat.com>
-rw-r--r-- | cli/src/connections.c | 10 | ||||
-rw-r--r-- | cli/src/devices.c | 8 | ||||
-rw-r--r-- | cli/src/network-manager.c | 16 |
3 files changed, 17 insertions, 17 deletions
diff --git a/cli/src/connections.c b/cli/src/connections.c index 972c9c3cf5..5ed43cb90f 100644 --- a/cli/src/connections.c +++ b/cli/src/connections.c @@ -7290,7 +7290,11 @@ parse_cmd (NmCli *nmc, int argc, char **argv) goto opt_error; nmc->return_value = do_connections_show (nmc, argc, argv); } else { - if (matches (*argv, "show") == 0) { + if (nmc_arg_is_help (*argv)) { + usage (); + nmc->should_wait = FALSE; + } + else if (matches (*argv, "show") == 0) { arg_ret = next_arg (&argc, &argv); if (arg_ret != 0 || matches (*argv, "configured") == 0) { next_arg (&argc, &argv); @@ -7334,10 +7338,6 @@ parse_cmd (NmCli *nmc, int argc, char **argv) else if (matches (*argv, "modify") == 0) { nmc->return_value = do_connection_modify (nmc, argc-1, argv+1); } - else if (nmc_arg_is_help (*argv)) { - usage (); - nmc->should_wait = FALSE; - } else { usage (); g_string_printf (nmc->return_text, _("Error: '%s' is not valid 'connection' command."), *argv); diff --git a/cli/src/devices.c b/cli/src/devices.c index b0e9f510e6..a21660d79a 100644 --- a/cli/src/devices.c +++ b/cli/src/devices.c @@ -2427,7 +2427,10 @@ do_devices (NmCli *nmc, int argc, char **argv) } if (argc > 0) { - if (matches (*argv, "status") == 0) { + if (nmc_arg_is_help (*argv)) { + usage (); + } + else if (matches (*argv, "status") == 0) { if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error)) goto opt_error; nmc->return_value = do_devices_status (nmc, argc-1, argv+1); @@ -2455,9 +2458,6 @@ do_devices (NmCli *nmc, int argc, char **argv) nmc->return_value = do_device_wimax (nmc, argc-1, argv+1); } #endif - else if (nmc_arg_is_help (*argv)) { - usage (); - } else { usage (); g_string_printf (nmc->return_text, _("Error: 'dev' command '%s' is not valid."), *argv); diff --git a/cli/src/network-manager.c b/cli/src/network-manager.c index 0275738c2e..272543f745 100644 --- a/cli/src/network-manager.c +++ b/cli/src/network-manager.c @@ -463,7 +463,10 @@ do_general (NmCli *nmc, int argc, char **argv) } if (argc > 0) { - if (matches (*argv, "status") == 0) { + if (nmc_arg_is_help (*argv)) { + usage_general (); + } + else if (matches (*argv, "status") == 0) { if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error)) { g_string_printf (nmc->return_text, _("Error: %s."), error->message); nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; @@ -514,9 +517,6 @@ do_general (NmCli *nmc, int argc, char **argv) } } } - else if (nmc_arg_is_help (*argv)) { - usage_general (); - } else { usage_general (); g_string_printf (nmc->return_text, _("Error: 'general' command '%s' is not valid."), *argv); @@ -645,7 +645,10 @@ do_radio (NmCli *nmc, int argc, char **argv) } if (argc > 0) { - if (matches (*argv, "all") == 0) { + if (nmc_arg_is_help (*argv)) { + usage_radio (); + } + else if (matches (*argv, "all") == 0) { if (next_arg (&argc, &argv) != 0) { /* no argument, show all radio switches */ if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error)) { @@ -703,9 +706,6 @@ do_radio (NmCli *nmc, int argc, char **argv) } } #endif - else if (nmc_arg_is_help (*argv)) { - usage_radio (); - } else { usage_radio (); g_string_printf (nmc->return_text, _("Error: 'radio' command '%s' is not valid."), *argv); |