summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <sha@pengutronix.de>2009-10-17 12:23:03 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2009-10-19 10:18:52 +0200
commit0ecf7f1aeb906e3b30500080fbc4e1d1b770f1a2 (patch)
treeab30c93958c0cc3b2191d564d36fc30ecdb221ee
parentcf996861d76fd7156c5bc096c68c62110f4531d7 (diff)
downloadbarebox-0ecf7f1aeb906e3b30500080fbc4e1d1b770f1a2.tar.gz
barebox-0ecf7f1aeb906e3b30500080fbc4e1d1b770f1a2.tar.xz
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>
-rw-r--r--common/command.c8
-rw-r--r--include/command.h4
2 files changed, 11 insertions, 1 deletions
diff --git a/common/command.c b/common/command.c
index 24c2e2407f..52b9ee14ef 100644
--- a/common/command.c
+++ b/common/command.c
@@ -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 */
diff --git a/include/command.h b/include/command.h
index aaae6b4309..5d57ecdeb5 100644
--- a/include/command.h
+++ b/include/command.h
@@ -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__ */
/*