浏览代码

Make "usage" messages more helpful.

In case of incorrect command invocations U-Boot used to print pretty
useless "usage" messages, for example:

	=> nand markbad
	Usage:
	nand - NAND sub-system

In the result, the user would have to run the "help" command to get
the (available) information about correct command usage. Change this,
so that this information gets always printed.

Note that this changes the user interface of all commands, but
hopefully to the better.

Signed-off-by: Wolfgang Denk <wd@denx.de>
Wolfgang Denk 16 年之前
父节点
当前提交
94796d8544
共有 2 个文件被更改,包括 17 次插入18 次删除
  1. 16 17
      common/command.c
  2. 1 1
      include/command.h

+ 16 - 17
common/command.c

@@ -286,21 +286,7 @@ int _do_help (cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t * cmdtp, int
 	 */
 	 */
 	for (i = 1; i < argc; ++i) {
 	for (i = 1; i < argc; ++i) {
 		if ((cmdtp = find_cmd_tbl (argv[i], cmd_start, cmd_items )) != NULL) {
 		if ((cmdtp = find_cmd_tbl (argv[i], cmd_start, cmd_items )) != NULL) {
-#ifdef	CONFIG_SYS_LONGHELP
-			/* found - print (long) help info */
-			puts (cmdtp->name);
-			putc (' ');
-			if (cmdtp->help) {
-				puts (cmdtp->help);
-			} else {
-				puts ("- No help available.\n");
-				rcode = 1;
-			}
-			putc ('\n');
-#else	/* no long help available */
-			if (cmdtp->usage)
-				printf ("%s - %s\n", cmdtp->name, cmdtp->usage);
-#endif	/* CONFIG_SYS_LONGHELP */
+			rcode |= cmd_usage(cmdtp);
 		} else {
 		} else {
 			printf ("Unknown command '%s' - try 'help'"
 			printf ("Unknown command '%s' - try 'help'"
 				" without arguments for list of all"
 				" without arguments for list of all"
@@ -386,9 +372,22 @@ cmd_tbl_t *find_cmd (const char *cmd)
 	return find_cmd_tbl(cmd, &__u_boot_cmd_start, len);
 	return find_cmd_tbl(cmd, &__u_boot_cmd_start, len);
 }
 }
 
 
-void cmd_usage(cmd_tbl_t *cmdtp)
+int cmd_usage(cmd_tbl_t *cmdtp)
 {
 {
-	printf("Usage:\n%s - %s\n\n", cmdtp->name, cmdtp->usage);
+	printf("%s - %s\n\n", cmdtp->name, cmdtp->usage);
+
+#ifdef	CONFIG_SYS_LONGHELP
+	printf("Usage:\n%s ", cmdtp->name);
+
+	if (!cmdtp->help) {
+		puts ("- No additional help available.\n");
+		return 1;
+	}
+
+	puts (cmdtp->help);
+	putc ('\n');
+#endif	/* CONFIG_SYS_LONGHELP */
+	return 0;
 }
 }
 
 
 #ifdef CONFIG_AUTO_COMPLETE
 #ifdef CONFIG_AUTO_COMPLETE

+ 1 - 1
include/command.h

@@ -71,7 +71,7 @@ int _do_help (cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t * cmdtp, int
 cmd_tbl_t *find_cmd(const char *cmd);
 cmd_tbl_t *find_cmd(const char *cmd);
 cmd_tbl_t *find_cmd_tbl (const char *cmd, cmd_tbl_t *table, int table_len);
 cmd_tbl_t *find_cmd_tbl (const char *cmd, cmd_tbl_t *table, int table_len);
 
 
-extern void cmd_usage(cmd_tbl_t *cmdtp);
+extern int cmd_usage(cmd_tbl_t *cmdtp);
 
 
 #ifdef CONFIG_AUTO_COMPLETE
 #ifdef CONFIG_AUTO_COMPLETE
 extern void install_auto_complete(void);
 extern void install_auto_complete(void);