Commit 7d5df73d authored by Jiří Klimeš's avatar Jiří Klimeš

cli: add nmc_arg_is_help() and use it to save some code lines

parent 83baf86a
......@@ -1761,9 +1761,7 @@ parse_cmd (NmCli *nmc, int argc, char **argv)
else if (matches(*argv, "delete") == 0) {
nmc->return_value = do_connection_delete (nmc, argc-1, argv+1);
}
else if ( matches (*argv, "help") == 0
|| (g_str_has_prefix (*argv, "-") && matches ((*argv)+1, "help") == 0)
|| (g_str_has_prefix (*argv, "--") && matches ((*argv)+2, "help") == 0)) {
else if (nmc_arg_is_help (*argv)) {
usage ();
nmc->should_wait = FALSE;
}
......
......@@ -2229,9 +2229,7 @@ do_devices (NmCli *nmc, int argc, char **argv)
nmc->return_value = do_device_wimax (nmc, argc-1, argv+1);
}
#endif
else if ( matches (*argv, "help") == 0
|| (g_str_has_prefix (*argv, "-") && matches ((*argv)+1, "help") == 0)
|| (g_str_has_prefix (*argv, "--") && matches ((*argv)+2, "help") == 0)) {
else if (nmc_arg_is_help (*argv)) {
usage ();
}
else {
......
......@@ -542,9 +542,7 @@ do_general (NmCli *nmc, int argc, char **argv)
}
}
}
else if ( matches (*argv, "help") == 0
|| (g_str_has_prefix (*argv, "-") && matches ((*argv)+1, "help") == 0)
|| (g_str_has_prefix (*argv, "--") && matches ((*argv)+2, "help") == 0)) {
else if (nmc_arg_is_help (*argv)) {
usage_general ();
}
else {
......@@ -611,9 +609,7 @@ do_networking (NmCli *nmc, int argc, char **argv)
if (argc == 0)
nmc_switch_show (nmc, NMC_FIELDS_NM_NETWORKING, _("Networking"));
else if (argc > 0) {
if ( matches (*argv, "help") == 0
|| (g_str_has_prefix (*argv, "-") && matches ((*argv)+1, "help") == 0)
|| (g_str_has_prefix (*argv, "--") && matches ((*argv)+2, "help") == 0)) {
if (nmc_arg_is_help (*argv)) {
usage_networking ();
} else if (nmc_switch_parse_on_off (nmc, *(argv-1), *argv, &enable_flag)) {
......@@ -708,9 +704,7 @@ do_radio (NmCli *nmc, int argc, char **argv)
}
}
#endif
else if ( matches (*argv, "help") == 0
|| (g_str_has_prefix (*argv, "-") && matches ((*argv)+1, "help") == 0)
|| (g_str_has_prefix (*argv, "--") && matches ((*argv)+2, "help") == 0)) {
else if (nmc_arg_is_help (*argv)) {
usage_radio ();
}
else {
......@@ -957,9 +951,7 @@ do_network_manager (NmCli *nmc, int argc, char **argv)
}
}
#endif
else if ( matches (*argv, "help") == 0
|| (g_str_has_prefix (*argv, "-") && matches ((*argv)+1, "help") == 0)
|| (g_str_has_prefix (*argv, "--") && matches ((*argv)+2, "help") == 0)) {
else if (nmc_arg_is_help (*argv)) {
usage ();
}
else {
......
......@@ -57,6 +57,17 @@ next_arg (int *argc, char ***argv)
return 0;
}
gboolean
nmc_arg_is_help (const char *arg)
{
if ( matches (arg, "help") == 0
|| (g_str_has_prefix (arg, "-") && matches (arg+1, "help") == 0)
|| (g_str_has_prefix (arg, "--") && matches (arg+2, "help") == 0)) {
return TRUE;
}
return FALSE;
}
/*
* Helper function to parse command-line arguments.
* arg_arr: description of arguments to look for
......
......@@ -37,6 +37,7 @@ typedef struct {
/* === Functions === */
int matches (const char *cmd, const char *pattern);
int next_arg (int *argc, char ***argv);
gboolean nmc_arg_is_help (const char *arg);
gboolean nmc_parse_args (nmc_arg_t *arg_arr, gboolean last, int *argc, char ***argv, GError **error);
char *ssid_to_printable (const char *str, gsize len);
char *nmc_ip4_address_as_string (guint32 ip, GError **error);
......
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