summaryrefslogtreecommitdiffstats
path: root/commands/global.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2016-09-21 08:50:05 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2016-09-22 11:31:21 +0200
commit62ae0274dfe6af959bbd70a9b30f885a7340a3c7 (patch)
tree9b6c5c1c5dcaa92a5ae6ff7b9cf124ddb6d04dca /commands/global.c
parent0ad0baac55f7aa39a9b629abb90973745564afc6 (diff)
downloadbarebox-62ae0274dfe6af959bbd70a9b30f885a7340a3c7.tar.gz
global: Make 'global' command behaviour consistent to 'nv'
The 'nv' command can add/remove multiple variables. Implement that for the 'global' command aswell. Also with the 'nv' command the -r option is for removal of variables, not for "set match". Looking at the users of "global -r" the only user uses the command for removal of variables and not for "Setting multiple variables to the same value" as stated in the command help text. Let "global -r" remove variables aswell. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands/global.c')
-rw-r--r--commands/global.c35
1 files changed, 17 insertions, 18 deletions
diff --git a/commands/global.c b/commands/global.c
index 581913d..d21b829 100644
--- a/commands/global.c
+++ b/commands/global.c
@@ -25,14 +25,14 @@
static int do_global(int argc, char *argv[])
{
- int opt;
- int do_set_match = 0;
+ int opt, i;
+ int do_remove = 0;
char *value;
while ((opt = getopt(argc, argv, "r")) > 0) {
switch (opt) {
case 'r':
- do_set_match = 1;
+ do_remove = 1;
break;
}
}
@@ -45,37 +45,36 @@ static int do_global(int argc, char *argv[])
argc -= optind;
argv += optind;
- if (argc != 1)
+ if (argc < 1)
return COMMAND_ERROR_USAGE;
- value = strchr(argv[0], '=');
- if (value) {
- *value = 0;
- value++;
- }
-
- if (do_set_match) {
- if (!value)
- value = "";
+ for (i = 0; i < argc; i++) {
+ value = strchr(argv[i], '=');
+ if (value) {
+ *value = 0;
+ value++;
+ }
- globalvar_set_match(argv[0], value);
- return 0;
+ if (do_remove)
+ globalvar_remove(argv[i]);
+ else
+ globalvar_add_simple(argv[i], value);
}
- return globalvar_add_simple(argv[0], value);
+ return 0;
}
BAREBOX_CMD_HELP_START(global)
BAREBOX_CMD_HELP_TEXT("Add a new global variable named VAR, optionally set to VALUE.")
BAREBOX_CMD_HELP_TEXT("")
BAREBOX_CMD_HELP_TEXT("Options:")
-BAREBOX_CMD_HELP_OPT("-r", "set value of all global variables beginning with 'match'")
+BAREBOX_CMD_HELP_OPT("-r", "Remove globalvars")
BAREBOX_CMD_HELP_END
BAREBOX_CMD_START(global)
.cmd = do_global,
BAREBOX_CMD_DESC("create or set global variables")
- BAREBOX_CMD_OPTS("[-r] VAR[=VALUE]")
+ BAREBOX_CMD_OPTS("[-r] VAR[=VALUE] ...")
BAREBOX_CMD_GROUP(CMD_GRP_ENV)
BAREBOX_CMD_HELP(cmd_global_help)
BAREBOX_CMD_END