From 62ae0274dfe6af959bbd70a9b30f885a7340a3c7 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Wed, 21 Sep 2016 08:50:05 +0200 Subject: 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 --- commands/global.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) (limited to 'commands/global.c') diff --git a/commands/global.c b/commands/global.c index 581913d289..d21b82951c 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 -- cgit v1.2.3