shared/shell: Fix parsing of mandatory arguments
In certain cases the arguments may no start with the mandatory commands
such as when the command handler expects getopt arguments first.
diff --git a/src/shared/shell.c b/src/shared/shell.c
index b9563ea..fc4c9b5 100644
--- a/src/shared/shell.c
+++ b/src/shared/shell.c
@@ -297,11 +297,22 @@
}
len = man - entry->arg;
- man = strndup(entry->arg, len + 1);
+ if (entry->arg[0] == '<')
+ man = strndup(entry->arg, len + 1);
+ else {
+ /* Find where mandatory arguments start */
+ opt = strrchr(entry->arg, '<');
+ /* Skip if mandatory arguments are not in the right format */
+ if (!opt || opt > man) {
+ opt = strdup(entry->arg);
+ goto optional;
+ }
+ man = strndup(opt, man - opt + 1);
+ }
if (parse_args(man, &w, "<>", flags) < 0) {
print_text(COLOR_HIGHLIGHT,
- "Unable to parse mandatory command arguments");
+ "Unable to parse mandatory command arguments: %s", man );
return -EINVAL;
}
@@ -318,7 +329,7 @@
optional:
if (parse_args(opt, &w, "[]", flags) < 0) {
print_text(COLOR_HIGHLIGHT,
- "Unable to parse optional command arguments");
+ "Unable to parse optional command arguments: %s", opt);
return -EINVAL;
}