[U-Boot] [PATCH 1/2] tools/env: allow option "-n" for fw_printenv

In commit bd7b26f8 (Tools: set multiple variable with fw_setenv utility), the option parsing was changed to getopt_long(3), but option "-n" of fw_printenv was not included.
This leads to an error message "invalid option -- 'n'" on stderr, although the output on stdout is correct.
Signed-off-by: Daniel Hobi daniel.hobi@schmid-telecom.ch --- tools/env/fw_env_main.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/tools/env/fw_env_main.c b/tools/env/fw_env_main.c index 82116b4..baf3a4d 100644 --- a/tools/env/fw_env_main.c +++ b/tools/env/fw_env_main.c @@ -59,7 +59,7 @@ void usage(void)
fprintf(stderr, "fw_printenv/fw_setenv, " "a command line interface to U-Boot environment\n\n" - "usage:\tfw_printenv\n" + "usage:\tfw_printenv [-n] [variable name]\n" "\tfw_setenv [variable name] [variable value]\n" "\tfw_setenv -s [ file ]\n" "\tfw_setenv -s - < [ file ]\n\n" @@ -93,9 +93,12 @@ main(int argc, char *argv[]) cmdname = p + 1; }
- while ((c = getopt_long (argc, argv, "s:h", + while ((c = getopt_long (argc, argv, "ns:h", long_options, NULL)) != EOF) { switch (c) { + case 'n': + /* handled in fw_printenv */ + break; case 's': script_file = optarg; break;

Signed-off-by: Daniel Hobi daniel.hobi@schmid-telecom.ch --- tools/env/fw_env_main.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/tools/env/fw_env_main.c b/tools/env/fw_env_main.c index baf3a4d..381ed14 100644 --- a/tools/env/fw_env_main.c +++ b/tools/env/fw_env_main.c @@ -105,6 +105,8 @@ main(int argc, char *argv[]) case 'h': usage(); return EXIT_SUCCESS; + default: /* '?' */ + return EXIT_FAILURE; } }

Dear Daniel Hobi,
In message 1284572787-9842-2-git-send-email-daniel.hobi@schmid-telecom.ch you wrote:
Signed-off-by: Daniel Hobi daniel.hobi@schmid-telecom.ch
tools/env/fw_env_main.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/tools/env/fw_env_main.c b/tools/env/fw_env_main.c index baf3a4d..381ed14 100644 --- a/tools/env/fw_env_main.c +++ b/tools/env/fw_env_main.c @@ -105,6 +105,8 @@ main(int argc, char *argv[]) case 'h': usage(); return EXIT_SUCCESS;
default: /* '?' */
return EXIT_FAILURE;
This should print an error message before returning; for example, run usage() as in the 'h' case - just with different return code.
Best regards,
Wolfgang Denk

Signed-off-by: Daniel Hobi daniel.hobi@schmid-telecom.ch --- v2: - print a hint to --help before returning
tools/env/fw_env_main.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
Hi Wolfgang,
On 15.09.2010 21:18, Wolfgang Denk wrote:
In message 1284572787-9842-2-git-send-email-daniel.hobi@schmid-telecom.ch you wrote:
default: /* '?' */
return EXIT_FAILURE;
This should print an error message before returning; for example, run usage() as in the 'h' case - just with different return code.
getopt_long(3) already prints a suitable error message (also see [PATCH 1/2]):
$ fw_printenv -a fw_printenv: invalid option -- 'a'
v2 of this patch additionally prints a hint to the user, in the same way as some Linux core utilities (Debian coreutils: cat, date and 94 others).
I prefer this solution to calling usage() which would hide the real error message by printing 20 additional lines.
Best regards, Daniel
diff --git a/tools/env/fw_env_main.c b/tools/env/fw_env_main.c index baf3a4d..c654057 100644 --- a/tools/env/fw_env_main.c +++ b/tools/env/fw_env_main.c @@ -105,6 +105,10 @@ main(int argc, char *argv[]) case 'h': usage(); return EXIT_SUCCESS; + default: /* '?' */ + fprintf(stderr, "Try `%s --help' for more information." + "\n", cmdname); + return EXIT_FAILURE; } }

Dear Daniel Hobi,
In message 1284640569-8527-1-git-send-email-daniel.hobi@schmid-telecom.ch you wrote:
Signed-off-by: Daniel Hobi daniel.hobi@schmid-telecom.ch
v2:
- print a hint to --help before returning
tools/env/fw_env_main.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
Applied, thanks.
Best regards,
Wolfgang Denk

Dear Daniel Hobi,
In message 1284572787-9842-1-git-send-email-daniel.hobi@schmid-telecom.ch you wrote:
In commit bd7b26f8 (Tools: set multiple variable with fw_setenv utility), the option parsing was changed to getopt_long(3), but option "-n" of fw_printenv was not included.
This leads to an error message "invalid option -- 'n'" on stderr, although the output on stdout is correct.
Signed-off-by: Daniel Hobi daniel.hobi@schmid-telecom.ch
tools/env/fw_env_main.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-)
Applied, thanks.
Best regards,
Wolfgang Denk
participants (2)
-
Daniel Hobi
-
Wolfgang Denk