aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2013-05-08 23:19:45 -0500
committerRob Landley <rob@landley.net>2013-05-08 23:19:45 -0500
commit09ee264817b4331a02279a9a5c9af6f2e846c37f (patch)
tree60ea669629cd8d45b45db6fa29da4e9921c44788
parent0b87b2e71324a20bdb7839ac95742d6208d5c321 (diff)
downloadtoybox-09ee264817b4331a02279a9a5c9af6f2e846c37f.tar.gz
Add --help option to toybox command when TOYBOX_HELP is enabled.
-rw-r--r--main.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/main.c b/main.c
index ac49e9b6..b0b2bb21 100644
--- a/main.c
+++ b/main.c
@@ -99,8 +99,7 @@ void toy_exec(char *argv[])
{
struct toy_list *which;
- which = toy_find(argv[0]);
- if (!which) return;
+ if (!(which = toy_find(argv[0]))) return;
toy_init(which, argv);
toys.which->toy_main();
if (fflush(NULL) || ferror(stdout)) perror_exit("write");
@@ -117,12 +116,21 @@ void toybox_main(void)
toys.which = toy_list;
if (toys.argv[1]) {
- if (toys.argv[1][0]!='-') {
+ if (CFG_TOYBOX_HELP && !strcmp(toys.argv[1], "--help")) {
+ if (toys.argv[2]) toys.which = toy_find(toys.argv[2]);
+ if (toys.which) {
+ show_help();
+ return;
+ }
+ } else {
toy_exec(toys.argv+1);
- error_exit("Unknown command %s",toys.argv[1]);
+ if (toys.argv[1][0] == '-') goto list;
}
+
+ error_exit("Unknown command %s",toys.argv[1]);
}
+list:
// Output list of command.
for (i=1; i<ARRAY_LEN(toy_list); i++) {
int fl = toy_list[i].flags;