Commit c9cfbae1 authored by Thomas Haller's avatar Thomas Haller

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's avatarThomas Haller <thaller@redhat.com>
parent 93131b1d
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment