From: Christian Couder <christian.couder@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
Patrick Steinhardt <ps@pks.im>, Elijah Newren <newren@gmail.com>,
Jeff King <peff@peff.net>,
"brian m . carlson" <sandals@crustytoothpaste.net>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>,
Justin Tobler <jltobler@gmail.com>,
Christian Couder <christian.couder@gmail.com>,
Christian Couder <chriscool@tuxfamily.org>
Subject: [PATCH 2/7] api-parse-options.adoc: document per-option flags
Date: Thu, 16 Jul 2026 18:55:12 +0200 [thread overview]
Message-ID: <20260716165517.433849-3-christian.couder@gmail.com> (raw)
In-Reply-To: <20260716165517.433849-1-christian.couder@gmail.com>
The "Flags" section in "Documentation/technical/api-parse-options.adoc"
documents the flags that can be passed to parse_options() itself. It
does not, however, document the flags that can be set on individual
options through the `flags` member of `struct option` (and through the
`OPT_*_F()` macro variants).
These per-option flags are used throughout the codebase (for example
`PARSE_OPT_HIDDEN` is used to hide an option from `-h` while still
showing it with `--help-all`), but a reader currently has to dig into
"parse-options.h" to find them.
To remediate that, let's add an "Option flags" subsection to the
"Data Structure" section, just before the list of option macros.
Let's also make it explicit that these are distinct from the
parse_options() flags described earlier, and let's describe the `-h`
versus `--help-all` behavior for `PARSE_OPT_HIDDEN`.
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
.../technical/api-parse-options.adoc | 61 +++++++++++++++++++
1 file changed, 61 insertions(+)
diff --git a/Documentation/technical/api-parse-options.adoc b/Documentation/technical/api-parse-options.adoc
index 880eb94642..fb4580e755 100644
--- a/Documentation/technical/api-parse-options.adoc
+++ b/Documentation/technical/api-parse-options.adoc
@@ -150,6 +150,67 @@ Data Structure
The main data structure is an array of the `option` struct,
say `static struct option builtin_add_options[]`.
+
+Option flags
+~~~~~~~~~~~~
+
+Each option can carry flags in the `flags` field of its `option`
+struct. These are per-option flags and are distinct from the
+`parse_options()` flags described above; they are usually set through
+the `OPT_*_F()` macro variants (see below) rather than by hand. They
+are the bitwise-or of:
+
+`PARSE_OPT_OPTARG`::
+ The option's argument is optional, i.e. both `--option` and
+ `--option=<value>` are accepted.
+
+`PARSE_OPT_NOARG`::
+ The option takes no argument at all. Using `--option=<value>`
+ is rejected.
+
+`PARSE_OPT_NONEG`::
+ Disable the automatically generated negated `--no-option`
+ form.
+
+`PARSE_OPT_HIDDEN`::
+ Hide the option: it is omitted from the usage shown by
+ `git <cmd> -h`, but is still shown by `git <cmd> --help-all`.
+ The option is parsed as usual either way. This is meant for
+ deprecated, advanced or otherwise uncommon options.
+
+`PARSE_OPT_LASTARG_DEFAULT`::
+ Use the default value (`defval`) when the option is used
+ without an argument, even for an option that normally requires
+ one. Only the last argument on the command line takes effect.
+
+`PARSE_OPT_NODASH`::
+ The option is a single character without a leading dash, such
+ as the `+` used by some commands.
+
+`PARSE_OPT_LITERAL_ARGHELP`::
+ Use the argument help string (`argh`) verbatim in the usage
+ output instead of surrounding it with `<>` or `[]`. Useful when
+ `argh` already contains a hand-formatted description.
+
+`PARSE_OPT_FROM_ALIAS`::
+ Internal flag, set on options that were expanded from a
+ configured alias. It should not be set by callers.
+
+`PARSE_OPT_NOCOMPLETE`::
+ Do not offer this option for completion.
+
+`PARSE_OPT_COMP_ARG`::
+ The option's argument, rather than the option itself, is what
+ should be completed.
+
+`PARSE_OPT_CMDMODE`::
+ The option is one of several mutually exclusive "command mode"
+ options that share the same variable. Using more than one of
+ them at once is rejected.
+
+Macros
+~~~~~~
+
There are some macros to easily define options:
`OPT__ABBREV(&int_var)`::
--
2.55.0.185.g9120d2b5c0
next prev parent reply other threads:[~2026-07-16 16:55 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-16 16:55 [PATCH 0/7] fast-import: standardize usage string and SYNOPSIS Christian Couder
2026-07-16 16:55 ` [PATCH 1/7] parse-options: introduce OPT_HIDDEN_GROUP Christian Couder
2026-07-16 21:14 ` Junio C Hamano
2026-07-16 22:14 ` .mailmap etiquette (was "Re: [PATCH 1/7] parse-options: introduce OPT_HIDDEN_GROUP") D. Ben Knoble
2026-07-16 22:31 ` Junio C Hamano
2026-07-16 16:55 ` Christian Couder [this message]
2026-07-16 16:55 ` [PATCH 3/7] api-parse-options.adoc: document hidden and OPT_*_F option macros Christian Couder
2026-07-16 16:55 ` [PATCH 4/7] fast-import: localize 'i' into the 'for' loops using it Christian Couder
2026-07-16 16:55 ` [PATCH 5/7] fast-import: introduce 'struct fast_import_state' Christian Couder
2026-07-16 16:55 ` [PATCH 6/7] fast-import: move command state globals into " Christian Couder
2026-07-16 16:55 ` [PATCH 7/7] fast-import: use struct option for usage string Christian Couder
2026-07-16 21:35 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260716165517.433849-3-christian.couder@gmail.com \
--to=christian.couder@gmail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=chriscool@tuxfamily.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jltobler@gmail.com \
--cc=newren@gmail.com \
--cc=peff@peff.net \
--cc=ps@pks.im \
--cc=sandals@crustytoothpaste.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox