From ab425de1c3e7d2f963f9da632ec88c79467acafb Mon Sep 17 00:00:00 2001 From: Pawel Szewczyk Date: Wed, 13 Aug 2014 13:46:49 +0200 Subject: [PATCH] gt: Make defining default function for command_parse possible It's not error, when standard command parse reach end of arguments list. We can define some non-help-printing behavior for this situation. Change-Id: Ib4bed570f385883d8cda5f79b648cfc31cef1e2a Signed-off-by: Pawel Szewczyk --- source/base/src/command.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/source/base/src/command.c b/source/base/src/command.c index c56124d..90808d8 100644 --- a/source/base/src/command.c +++ b/source/base/src/command.c @@ -29,7 +29,10 @@ static inline bool name_matches(const char *candidate, const char *pattern) { - // If string is NULL it suits to all strings + // If pattern is NULL it suits only to NULL + if (!pattern) + return !candidate; + // If candidate is NULL it suits to all strings return (candidate && (strcmp(candidate, pattern) == 0)) || (!candidate); } @@ -40,12 +43,6 @@ void command_parse(const Command *cmd, int argc, char **argv, const Command *next = cmd->getChildren(cmd); bool found = false; - // If there is nothing more to parse it's error - if (argc == 0) { - executable_command_set(exec, cmd->printHelp, data, NULL); - return; - } - while (next->parse) { if (name_matches(next->name, *argv)) { found = true; -- 2.7.4