U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Rasmus Villemoes <ravi@prevas.dk>
To: u-boot@lists.denx.de
Cc: Tom Rini <trini@konsulko.com>,
	Joe Hershberger <joe.hershberger@ni.com>,
	Ravi Minnikanti <rminnikanti@marvell.com>,
	Rasmus Villemoes <ravi@prevas.dk>
Subject: [PATCH 1/3] cmd/nvedit.c: teach 'env default' to optionally keep runtime variables
Date: Wed, 30 Oct 2024 22:34:02 +0100	[thread overview]
Message-ID: <20241030213404.2894247-2-ravi@prevas.dk> (raw)
In-Reply-To: <20241030213404.2894247-1-ravi@prevas.dk>

It can be useful to set all variables defined in the default
environment to the value they have there, but without removing
variables that are only defined at runtime. This can sort-of be done
today, by using the "env default var1 var2 ..." variant, but that
requires listing all variables defined in the default
environment. It's much more convenient to be able to say

  env default -k -a

The -k flag is also meaningful in the other case: If var1 is not
defined in the default environment, but var2 is,

  env default var1 var2

would emit a warning about var1 not being in the default env and thus
being deleted. With -k, there's no warning, and var1 is kept as-is.

Signed-off-by: Rasmus Villemoes <ravi@prevas.dk>
---
 cmd/nvedit.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/cmd/nvedit.c b/cmd/nvedit.c
index 392f90f8698..1f259801293 100644
--- a/cmd/nvedit.c
+++ b/cmd/nvedit.c
@@ -523,6 +523,9 @@ static int do_env_default(struct cmd_tbl *cmdtp, int flag,
 			case 'f':		/* force */
 				env_flag |= H_FORCE;
 				break;
+			case 'k':
+				env_flag |= H_NOCLEAR;
+				break;
 			default:
 				return cmd_usage(cmdtp);
 			}
@@ -1133,8 +1136,9 @@ U_BOOT_LONGHELP(env,
 #if defined(CONFIG_CMD_ENV_CALLBACK)
 	"callbacks - print callbacks and their associated variables\nenv "
 #endif
-	"default [-f] -a - [forcibly] reset default environment\n"
-	"env default [-f] var [...] - [forcibly] reset variable(s) to their default values\n"
+	"default [-k] [-f] -a - [forcibly] reset default environment\n"
+	"env default [-k] [-f] var [...] - [forcibly] reset variable(s) to their default values\n"
+	"      \"-k\": keep variables not defined in default environment\n"
 	"env delete [-f] var [...] - [forcibly] delete variable(s)\n"
 #if defined(CONFIG_CMD_EDITENV)
 	"env edit name - edit environment variable\n"
-- 
2.47.0


  reply	other threads:[~2024-10-30 21:34 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-30 21:34 [PATCH 0/3] teach 'env default' to optionally keep runtime variables Rasmus Villemoes
2024-10-30 21:34 ` Rasmus Villemoes [this message]
2024-10-30 21:34 ` [PATCH 2/3] test: env: check that non-mentioned variables to "env default" are preserved Rasmus Villemoes
2024-10-30 21:34 ` [PATCH 3/3] test: env: add some test cases for new "env default -k" flag Rasmus Villemoes
2024-11-13 22:32 ` [PATCH 0/3] teach 'env default' to optionally keep runtime variables Rasmus Villemoes
2024-11-15 14:21   ` Simon Glass
2024-11-15 15:22     ` Rasmus Villemoes
2024-11-16  3:41 ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241030213404.2894247-2-ravi@prevas.dk \
    --to=ravi@prevas.dk \
    --cc=joe.hershberger@ni.com \
    --cc=rminnikanti@marvell.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox