Improve cli_arg() diagnostic log messages

This commit is contained in:
Andrew Bettison 2013-02-14 16:00:47 +10:30
parent e86a129d49
commit 2d4133315d
2 changed files with 5 additions and 3 deletions

4
cli.c
View File

@ -193,7 +193,7 @@ int cli_invoke(const struct cli_parsed *parsed, void *context)
RETURN(ret);
}
int cli_arg(const struct cli_parsed *parsed, char *label, const char **dst, int (*validator)(const char *arg), char *defaultvalue)
int _cli_arg(struct __sourceloc __whence, const struct cli_parsed *parsed, char *label, const char **dst, int (*validator)(const char *arg), char *defaultvalue)
{
int labellen = strlen(label);
if (dst)
@ -203,7 +203,7 @@ int cli_arg(const struct cli_parsed *parsed, char *label, const char **dst, int
if (parsed->labelv[i].len == labellen && strncasecmp(label, parsed->labelv[i].label, labellen) == 0) {
const char *value = parsed->labelv[i].text;
if (validator && !(*validator)(value))
return WHYF("Invalid argument %d '%s': \"%s\"", i + 1, label, value);
return WHYF("Invalid '%s' argument \"%s\"", label, value);
if (dst)
*dst = value;
return 0;

4
cli.h
View File

@ -56,7 +56,9 @@ void _debug_cli_parsed(struct __sourceloc __whence, const struct cli_parsed *par
int cli_usage(const struct cli_schema *commands);
int cli_parse(const int argc, const char *const *args, const struct cli_schema *commands, struct cli_parsed *parsed);
int cli_invoke(const struct cli_parsed *parsed, void *context);
int cli_arg(const struct cli_parsed *parsed, char *label, const char **dst, int (*validator)(const char *arg), char *defaultvalue);
int _cli_arg(struct __sourceloc __whence, const struct cli_parsed *parsed, char *label, const char **dst, int (*validator)(const char *arg), char *defaultvalue);
#define cli_arg(parsed, label, dst, validator, defaultvalue) _cli_arg(__WHENCE__, parsed, label, dst, validator, defaultvalue)
int cli_lookup_did(const char *text);
int cli_absolute_path(const char *arg);