Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
b66fb1da 1f2ed153

+8
+3
tools/lib/subcmd/parse-options.c
··· 213 213 else 214 214 err = get_arg(p, opt, flags, (const char **)opt->value); 215 215 216 + if (opt->set) 217 + *(bool *)opt->set = true; 218 + 216 219 /* PARSE_OPT_NOEMPTY: Allow NULL but disallow empty string. */ 217 220 if (opt->flags & PARSE_OPT_NOEMPTY) { 218 221 const char *val = *(const char **)opt->value;
+5
tools/lib/subcmd/parse-options.h
··· 137 137 { .type = OPTION_STRING, .short_name = (s), .long_name = (l), \ 138 138 .value = check_vtype(v, const char **), (a), .help = (h), \ 139 139 .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 *)} 140 145 #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} 141 146 #define OPT_DATE(s, l, v, h) \ 142 147 { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), .argh = "time", .help = (h), .callback = parse_opt_approxidate_cb }