[U-Boot] [PATCH 2/2 v2] tools/env: fail on invalid options

Daniel Hobi daniel.hobi at schmid-telecom.ch
Thu Sep 16 14:36:09 CEST 2010


Signed-off-by: Daniel Hobi <daniel.hobi at 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 at 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;
 		}
 	}
 
-- 
1.7.2.3



More information about the U-Boot mailing list