9
0
Fork 0

commands: add defines for command errors/success

This allows us to return COMMAND_ERROR_USAGE for
a failed command which will then print the usage,
a very common case for commands.

Signed-off-by: Sascha Hauer <sha@pengutronix.de>
This commit is contained in:
Sascha Hauer 2009-10-17 12:23:03 +02:00 committed by Sascha Hauer
parent cf996861d7
commit 0ecf7f1aeb
2 changed files with 11 additions and 1 deletions

View File

@ -94,6 +94,7 @@ static int compare(struct list_head *a, struct list_head *b)
int execute_command(int argc, char **argv)
{
cmd_tbl_t *cmdtp;
int ret;
/* Look up command in command table */
if ((cmdtp = find_cmd(argv[0]))) {
@ -103,7 +104,12 @@ int execute_command(int argc, char **argv)
return -1;
}
/* OK - call function to do the command */
return cmdtp->cmd(cmdtp, argc, argv);
ret = cmdtp->cmd(cmdtp, argc, argv);
if (ret == COMMAND_ERROR_USAGE) {
u_boot_cmd_usage(cmdtp);
return COMMAND_ERROR;
}
return ret;
} else {
printf ("Unknown command '%s' - try 'help'\n", argv[0]);
return -1; /* give up after bad command */

View File

@ -74,6 +74,10 @@ cmd_tbl_t *find_cmd(const char *cmd);
int execute_command(int argc, char **argv);
void u_boot_cmd_usage(cmd_tbl_t *cmdtp);
#define COMMAND_SUCCESS 0
#define COMMAND_ERROR 1
#define COMMAND_ERROR_USAGE 2
#endif /* __ASSEMBLY__ */
/*