tools/env: allow option "-n" for fw_printenv
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.
--- tools/env/fw_env_main.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-)
tools/env/fw_env_main.c +5 -2
@@ -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 ;
Signature · 1 line
1.7.2.3
PATCH 2/2 tools/env: fail on invalid options
--- tools/env/fw_env_main.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
tools/env/fw_env_main.c +2 -0
@@ -105,6 +105,8 @@ main(int argc, char *argv[])case 'h' :usage ();return EXIT_SUCCESS ; +default :/* '?' */ +return EXIT_FAILURE ; } }
Signature · 1 line
1.7.2.3
PATCH 2/2 tools/env: fail on invalid options
Dear Daniel Hobi,
Quoted 11 lines · In message <[email protected]>…
Signed-off-by Daniel Hobi <[email protected]>--- tools/env/fw_env_main.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)tools/env/fw_env_main.c +0
-0
tools/env/fw_env_main.c main(int argc, char *argv[]) · line 109
Quoted 5 lines
tools/env/fw_env_main.c +2
-0@@ -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
Signature · 6 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de He had quite a powerful intellect, but it was as powerful like a locomotive, and ran on rails and was therefore almost impossible to steer. - Terry Pratchett, _Lords and Ladies_
PATCH v2 2/2 tools/env: fail on invalid options
---
v2:
- print a hint to --help before returning
tools/env/fw_env_main.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
Hi Wolfgang,
Quoted 6 lines · Wolfgang Denk
Review
Quoted 2 lines · In message <[email protected]>…
(quoted diff) +2
-0+ 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
tools/env/fw_env_main.c +4 -0
@@ -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 ; } }
Signature · 1 line
1.7.2.3
Wolfgang Denk
AppliedPATCH v2 2/2 tools/env: fail on invalid options
Dear Daniel Hobi,
Quoted 8 lines · In message <[email protected]>…
Signed-off-by Daniel Hobi <[email protected]>---
v2:
- print a hint to --help before returningtools/env/fw_env_main.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
Applied, thanks.
Best regards,
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de Certainly there are things in life that money can't buy, but it's very funny - Did you ever try buying them without money? - Ogden Nash
Wolfgang Denk
AppliedPATCH 1/2 tools/env: allow option "-n" for fw_printenv
In reply to Daniel HobiDear Daniel Hobi,
Quoted 11 lines · In message <[email protected]>…
In commit
bd7b26f8(Tools: set multiple variable withfw_setenvutility), the option parsing was changed togetopt_long(3), but option "-n" offw_printenvwas 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 <[email protected]>--- tools/env/fw_env_main.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-)
Applied, thanks.
Best regards,
Wolfgang Denk
Signature · 4 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de It's a small world, but I wouldn't want to paint it.