mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-02-21 09:51:50 +00:00
Improve cli_arg() diagnostic log messages
This commit is contained in:
parent
e86a129d49
commit
2d4133315d
4
cli.c
4
cli.c
@ -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
4
cli.h
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user