tools lib subcmd: Add OPT_STRING_OPTARG_SET option
To allow string options with a default argument and variable set when the option is used. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Tested-by: Wang Nan <wangnan0@huawei.com> Cc: David Ahern <dsahern@gmail.com> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lkml.kernel.org/r/1483431600-19887-2-git-send-email-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
1f2ed153b9
commit
b66fb1da5a
@ -213,6 +213,9 @@ static int get_value(struct parse_opt_ctx_t *p,
|
||||
else
|
||||
err = get_arg(p, opt, flags, (const char **)opt->value);
|
||||
|
||||
if (opt->set)
|
||||
*(bool *)opt->set = true;
|
||||
|
||||
/* PARSE_OPT_NOEMPTY: Allow NULL but disallow empty string. */
|
||||
if (opt->flags & PARSE_OPT_NOEMPTY) {
|
||||
const char *val = *(const char **)opt->value;
|
||||
|
@ -137,6 +137,11 @@ struct option {
|
||||
{ .type = OPTION_STRING, .short_name = (s), .long_name = (l), \
|
||||
.value = check_vtype(v, const char **), (a), .help = (h), \
|
||||
.flags = PARSE_OPT_OPTARG, .defval = (intptr_t)(d) }
|
||||
#define OPT_STRING_OPTARG_SET(s, l, v, os, a, h, d) \
|
||||
{ .type = OPTION_STRING, .short_name = (s), .long_name = (l), \
|
||||
.value = check_vtype(v, const char **), (a), .help = (h), \
|
||||
.flags = PARSE_OPT_OPTARG, .defval = (intptr_t)(d), \
|
||||
.set = check_vtype(os, bool *)}
|
||||
#define OPT_STRING_NOEMPTY(s, l, v, a, h) { .type = OPTION_STRING, .short_name = (s), .long_name = (l), .value = check_vtype(v, const char **), (a), .help = (h), .flags = PARSE_OPT_NOEMPTY}
|
||||
#define OPT_DATE(s, l, v, h) \
|
||||
{ .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), .argh = "time", .help = (h), .callback = parse_opt_approxidate_cb }
|
||||
|
Loading…
x
Reference in New Issue
Block a user