aboutsummaryrefslogtreecommitdiff
path: root/src/command.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/command.h')
-rw-r--r--src/command.h22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/command.h b/src/command.h
index b45f8b9..54ce16f 100644
--- a/src/command.h
+++ b/src/command.h
@@ -28,8 +28,8 @@
#define COMMAND_HELP(GROUP, MSG) \
COMMAND(GROUP, help) \
{ \
- fprintf(stderr, USAGE_STR MSG " <command>\n\nList of commands:\n"); \
- print_help(GROUP##_commands, ARRAY_LEN(GROUP##_commands)); \
+ fprintf(stderr, USAGE_STR MSG " <command>\n"); \
+ print_help(GROUP##_commands, ARRAY_LEN(GROUP##_commands), GROUP##_flags, ARRAY_LEN(GROUP##_flags)); \
return 0; \
}
@@ -58,7 +58,23 @@
{ \
for (unsigned long i = 0; i < ARRAY_LEN(GROUP##_commands); ++i) \
if (!strcmp(GROUP##_commands[i].name, argv[1])) return GROUP##_commands[i].func(argc-1, argv+1); \
- fprintf(stderr, NAME ": '%s' is not a command\n", argv[1]); \
+ \
+ for (int j = 1; j < argc; ++j) \
+ { \
+ if (argv[j][0] != '-') continue; \
+ \
+ for (unsigned long i = 0; i < ARRAY_LEN(GROUP##_flags); ++i) \
+ { \
+ if (GROUP##_flags[i].variant & SINGLE && argv[j][1] == GROUP##_flags[i].name[0] || \
+ GROUP##_flags[i].variant & DOUBLE && argv[j][1] == '-' \
+ && !strcmp(GROUP##_flags[i].name, argv[j]+2)) \
+ { \
+ return GROUP##_flags[i].func(0, NULL); \
+ } \
+ } \
+ } \
+ \
+ fprintf(stderr, NAME ": '%s' is not a command or flag\n", argv[1]); \
return 0; \
} \
return GROUP##_help(argc-1, argv+1); \