Skip to content

Commit 5f0df44

Browse files
rscharfegitster
authored andcommitted
parse-options: automatically infer PARSE_OPT_LITERAL_ARGHELP
Parseopt wraps argument help strings in a pair of angular brackets by default, to tell users that they need to replace it with an actual value. This is useful in most cases, because most option arguments are indeed single values of a certain type. The option PARSE_OPT_LITERAL_ARGHELP needs to be used in option definitions with arguments that have multiple parts or are literal strings. Stop adding these angular brackets if special characters are present, as they indicate that we don't deal with a simple placeholder. This simplifies the code a bit and makes defining special options slightly easier. Remove the flag PARSE_OPT_LITERAL_ARGHELP in the cases where the new and more cautious handling suffices. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b8ade4c commit 5f0df44

File tree

9 files changed

+12
-15
lines changed

9 files changed

+12
-15
lines changed

builtin/add.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,8 @@ static struct option builtin_add_options[] = {
306306
OPT_BOOL( 0 , "refresh", &refresh_only, N_("don't add, only refresh the index")),
307307
OPT_BOOL( 0 , "ignore-errors", &ignore_add_errors, N_("just skip files which cannot be added because of errors")),
308308
OPT_BOOL( 0 , "ignore-missing", &ignore_missing, N_("check if - even missing - files are ignored in dry run")),
309-
{ OPTION_STRING, 0, "chmod", &chmod_arg, "(+|-)x",
310-
N_("override the executable bit of the listed files"),
311-
PARSE_OPT_LITERAL_ARGHELP },
309+
OPT_STRING(0, "chmod", &chmod_arg, "(+|-)x",
310+
N_("override the executable bit of the listed files")),
312311
OPT_HIDDEN_BOOL(0, "warn-embedded-repo", &warn_on_embedded_repo,
313312
N_("warn when adding an embedded repository")),
314313
OPT_END(),

builtin/pack-objects.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2943,7 +2943,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
29432943
N_("similar to --all-progress when progress meter is shown")),
29442944
{ OPTION_CALLBACK, 0, "index-version", NULL, N_("<version>[,<offset>]"),
29452945
N_("write the pack index file in the specified idx format version"),
2946-
PARSE_OPT_LITERAL_ARGHELP, option_parse_index_version },
2946+
0, option_parse_index_version },
29472947
OPT_MAGNITUDE(0, "max-pack-size", &pack_size_limit,
29482948
N_("maximum size of each output pack file")),
29492949
OPT_BOOL(0, "local", &local,

builtin/read-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
134134
N_("same as -m, but discard unmerged entries")),
135135
{ OPTION_STRING, 0, "prefix", &opts.prefix, N_("<subdirectory>/"),
136136
N_("read the tree into the index under <subdirectory>/"),
137-
PARSE_OPT_NONEG | PARSE_OPT_LITERAL_ARGHELP },
137+
PARSE_OPT_NONEG },
138138
OPT_BOOL('u', NULL, &opts.update,
139139
N_("update working tree with merge result")),
140140
{ OPTION_CALLBACK, 0, "exclude-per-directory", &opts,

builtin/send-pack.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
179179
{ OPTION_CALLBACK,
180180
0, CAS_OPT_NAME, &cas, N_("<refname>:<expect>"),
181181
N_("require old value of ref to be at this value"),
182-
PARSE_OPT_OPTARG | PARSE_OPT_LITERAL_ARGHELP,
183-
parseopt_push_cas_option },
182+
PARSE_OPT_OPTARG, parseopt_push_cas_option },
184183
OPT_END()
185184
};
186185

builtin/shortlog.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,7 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
268268
OPT_BOOL('e', "email", &log.email,
269269
N_("Show the email address of each author")),
270270
{ OPTION_CALLBACK, 'w', NULL, &log, N_("<w>[,<i1>[,<i2>]]"),
271-
N_("Linewrap output"),
272-
PARSE_OPT_OPTARG | PARSE_OPT_LITERAL_ARGHELP,
271+
N_("Linewrap output"), PARSE_OPT_OPTARG,
273272
&parse_wrap_args },
274273
OPT_END(),
275274
};

builtin/show-branch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
655655
{ OPTION_CALLBACK, 'g', "reflog", &reflog_base, N_("<n>[,<base>]"),
656656
N_("show <n> most recent ref-log entries starting at "
657657
"base"),
658-
PARSE_OPT_OPTARG | PARSE_OPT_LITERAL_ARGHELP,
658+
PARSE_OPT_OPTARG,
659659
parse_reflog_param },
660660
OPT_END()
661661
};

builtin/update-index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
972972
(parse_opt_cb *) cacheinfo_callback},
973973
{OPTION_CALLBACK, 0, "chmod", &set_executable_bit, "(+|-)x",
974974
N_("override the executable bit of the listed files"),
975-
PARSE_OPT_NONEG | PARSE_OPT_LITERAL_ARGHELP,
975+
PARSE_OPT_NONEG,
976976
chmod_callback},
977977
{OPTION_SET_INT, 0, "assume-unchanged", &mark_valid_only, NULL,
978978
N_("mark files as \"not changing\""),

builtin/write-tree.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ int cmd_write_tree(int argc, const char **argv, const char *unused_prefix)
2424
struct option write_tree_options[] = {
2525
OPT_BIT(0, "missing-ok", &flags, N_("allow missing objects"),
2626
WRITE_TREE_MISSING_OK),
27-
{ OPTION_STRING, 0, "prefix", &prefix, N_("<prefix>/"),
28-
N_("write tree object for a subdirectory <prefix>") ,
29-
PARSE_OPT_LITERAL_ARGHELP },
27+
OPT_STRING(0, "prefix", &prefix, N_("<prefix>/"),
28+
N_("write tree object for a subdirectory <prefix>")),
3029
{ OPTION_BIT, 0, "ignore-cache-tree", &flags, NULL,
3130
N_("only useful for debugging"),
3231
PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, NULL,

parse-options.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,8 @@ int parse_options(int argc, const char **argv, const char *prefix,
562562
static int usage_argh(const struct option *opts, FILE *outfile)
563563
{
564564
const char *s;
565-
int literal = (opts->flags & PARSE_OPT_LITERAL_ARGHELP) || !opts->argh;
565+
int literal = (opts->flags & PARSE_OPT_LITERAL_ARGHELP) ||
566+
!opts->argh || !!strpbrk(opts->argh, "()<>[]|");
566567
if (opts->flags & PARSE_OPT_OPTARG)
567568
if (opts->long_name)
568569
s = literal ? "[=%s]" : "[=<%s>]";

0 commit comments

Comments
 (0)