cli: check for global options before each agument
Turn --ask and --show-secrets into global options. This is for user comfort, see: rh #1351263.
This commit is contained in:
@@ -231,8 +231,8 @@ process_command_line (NmCli *nmc, int argc, char **argv)
|
|||||||
|
|
||||||
if (argc == 1 && nmc->complete) {
|
if (argc == 1 && nmc->complete) {
|
||||||
nmc_complete_strings (opt, "--terse", "--pretty", "--mode", "--colors", "--escape",
|
nmc_complete_strings (opt, "--terse", "--pretty", "--mode", "--colors", "--escape",
|
||||||
"--fields", "--nocheck", "--ask", "--show-secrets",
|
"--fields", "--nocheck", "--get-values",
|
||||||
"--get-values", "--wait", "--version", "--help", NULL);
|
"--wait", "--version", "--help", NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opt[1] == '-') {
|
if (opt[1] == '-') {
|
||||||
@@ -360,10 +360,6 @@ process_command_line (NmCli *nmc, int argc, char **argv)
|
|||||||
nmc->mode_specified = TRUE;
|
nmc->mode_specified = TRUE;
|
||||||
} else if (matches (opt, "-nocheck")) {
|
} else if (matches (opt, "-nocheck")) {
|
||||||
/* ignore for backward compatibility */
|
/* ignore for backward compatibility */
|
||||||
} else if (matches (opt, "-ask")) {
|
|
||||||
nmc->ask = TRUE;
|
|
||||||
} else if (matches (opt, "-show-secrets")) {
|
|
||||||
nmc->show_secrets = TRUE;
|
|
||||||
} else if (matches (opt, "-wait")) {
|
} else if (matches (opt, "-wait")) {
|
||||||
unsigned long timeout;
|
unsigned long timeout;
|
||||||
if (!argc) {
|
if (!argc) {
|
||||||
|
@@ -28,6 +28,7 @@
|
|||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
matches (const char *cmd, const char *pattern)
|
matches (const char *cmd, const char *pattern)
|
||||||
@@ -38,17 +39,34 @@ matches (const char *cmd, const char *pattern)
|
|||||||
return memcmp (pattern, cmd, len) == 0;
|
return memcmp (pattern, cmd, len) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
parse_global_arg (NmCli *nmc, const char *arg)
|
||||||
|
{
|
||||||
|
if (nmc_arg_is_option (arg, "ask"))
|
||||||
|
nmc->ask = TRUE;
|
||||||
|
else if (nmc_arg_is_option (arg, "show-secrets"))
|
||||||
|
nmc->show_secrets = TRUE;
|
||||||
|
else
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
next_arg (NmCli *nmc, int *argc, char ***argv)
|
next_arg (NmCli *nmc, int *argc, char ***argv)
|
||||||
{
|
{
|
||||||
int arg_num = *argc;
|
int arg_num = *argc;
|
||||||
|
|
||||||
|
do {
|
||||||
if (arg_num > 0) {
|
if (arg_num > 0) {
|
||||||
(*argc)--;
|
(*argc)--;
|
||||||
(*argv)++;
|
(*argv)++;
|
||||||
}
|
}
|
||||||
|
if (nmc && nmc->complete && *argc == 1 && ***argv == '-')
|
||||||
|
nmc_complete_strings (**argv, "--ask", "--show-secrets", NULL);
|
||||||
if (arg_num <= 1)
|
if (arg_num <= 1)
|
||||||
return -1;
|
return -1;
|
||||||
|
} while (nmc && parse_global_arg (nmc, **argv));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -82,7 +100,6 @@ nmc_arg_is_option (const char *str, const char *opt_name)
|
|||||||
return (*p ? matches (p, opt_name) : FALSE);
|
return (*p ? matches (p, opt_name) : FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Helper function to parse command-line arguments.
|
* Helper function to parse command-line arguments.
|
||||||
* arg_arr: description of arguments to look for
|
* arg_arr: description of arguments to look for
|
||||||
|
Reference in New Issue
Block a user