Skip to content

Commit b66fb1d

Browse files
olsajiriacmel
authored andcommitted
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>
1 parent 1f2ed15 commit b66fb1d

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

‎tools/lib/subcmd/parse-options.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ static int get_value(struct parse_opt_ctx_t *p,
213213
else
214214
err = get_arg(p, opt, flags, (const char **)opt->value);
215215

216+
if (opt->set)
217+
*(bool *)opt->set = true;
218+
216219
/* PARSE_OPT_NOEMPTY: Allow NULL but disallow empty string. */
217220
if (opt->flags & PARSE_OPT_NOEMPTY) {
218221
const char *val = *(const char **)opt->value;

‎tools/lib/subcmd/parse-options.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ struct option {
137137
{ .type = OPTION_STRING, .short_name = (s), .long_name = (l), \
138138
.value = check_vtype(v, const char **), (a), .help = (h), \
139139
.flags = PARSE_OPT_OPTARG, .defval = (intptr_t)(d) }
140+
#define OPT_STRING_OPTARG_SET(s, l, v, os, a, h, d) \
141+
{ .type = OPTION_STRING, .short_name = (s), .long_name = (l), \
142+
.value = check_vtype(v, const char **), (a), .help = (h), \
143+
.flags = PARSE_OPT_OPTARG, .defval = (intptr_t)(d), \
144+
.set = check_vtype(os, bool *)}
140145
#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}
141146
#define OPT_DATE(s, l, v, h) \
142147
{ .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), .argh = "time", .help = (h), .callback = parse_opt_approxidate_cb }

0 commit comments

Comments
 (0)