summaryrefslogtreecommitdiffstats
path: root/commands/nv.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2016-07-22 11:49:48 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2016-07-22 12:27:22 +0200
commit0c2fccceb625655a0cbae40bfca3449914ff02cf (patch)
tree52a0356d869b6aa95c9de8cf29a53652a13b9935 /commands/nv.c
parent443f7fd65542e34a6c272022d0e5b9662d18b527 (diff)
downloadbarebox-0c2fccceb625655a0cbae40bfca3449914ff02cf.tar.gz
nv: Allow to set/remove multiple variables with one command
It's convenient to set/remove multiple nv variables in one go. With this patch we iterate over the remaining nonopts instead of expecting exactly one nonopt. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands/nv.c')
-rw-r--r--commands/nv.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/commands/nv.c b/commands/nv.c
index e312368..a1fb095 100644
--- a/commands/nv.c
+++ b/commands/nv.c
@@ -27,7 +27,7 @@ static int do_nv(int argc, char *argv[])
{
int opt;
int do_remove = 0, do_save = 0;
- int ret;
+ int ret, i;
char *value;
while ((opt = getopt(argc, argv, "rs")) > 0) {
@@ -54,19 +54,21 @@ static int do_nv(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++;
- }
+ for (i = 0; i < argc; i++) {
+ value = strchr(argv[0], '=');
+ if (value) {
+ *value = 0;
+ value++;
+ }
- if (do_remove)
- ret = nvvar_remove(argv[0]);
- else
- ret = nvvar_add(argv[0], value);
+ if (do_remove)
+ ret = nvvar_remove(argv[i]);
+ else
+ ret = nvvar_add(argv[i], value);
+ }
return ret;
}
@@ -78,14 +80,14 @@ BAREBOX_CMD_HELP_TEXT("global variables of the same name. Their value is saved i
BAREBOX_CMD_HELP_TEXT("'saveenv' or explicitly with 'nv -s'")
BAREBOX_CMD_HELP_TEXT("")
BAREBOX_CMD_HELP_TEXT("Options:")
-BAREBOX_CMD_HELP_OPT("-r", "remove a non volatile variable")
+BAREBOX_CMD_HELP_OPT("-r", "remove non volatile variables")
BAREBOX_CMD_HELP_OPT("-s", "Save NV variables")
BAREBOX_CMD_HELP_END
BAREBOX_CMD_START(nv)
.cmd = do_nv,
BAREBOX_CMD_DESC("create or set non volatile variables")
- BAREBOX_CMD_OPTS("[-r] VAR[=VALUE]")
+ BAREBOX_CMD_OPTS("[-r] VAR[=VALUE] ...")
BAREBOX_CMD_GROUP(CMD_GRP_ENV)
BAREBOX_CMD_HELP(cmd_nv_help)
BAREBOX_CMD_END