Home Explore Blog CI



git

5th chunk of `Documentation/git-rev-parse.adoc`
211e776b4dfd9cf727e962b5add9533170f83cfc0485b1f500000001000009b5
 the date string, and output the corresponding
	--min-age= parameter for 'git rev-list'.

<arg>...::
	Flags and parameters to be parsed.


include::revisions.adoc[]

PARSEOPT
--------

In `--parseopt` mode, 'git rev-parse' helps massaging options to bring to shell
scripts the same facilities C builtins have. It works as an option normalizer
(e.g. splits single switches aggregate values), a bit like `getopt(1)` does.

It takes on the standard input the specification of the options to parse and
understand, and echoes on the standard output a string suitable for `sh(1)` `eval`
to replace the arguments with normalized ones.  In case of error, it outputs
usage on the standard error stream, and exits with code 129.

Note: Make sure you quote the result when passing it to `eval`.  See
below for an example.

Input Format
~~~~~~~~~~~~

'git rev-parse --parseopt' input format is fully text based. It has two parts,
separated by a line that contains only `--`. The lines before the separator
(should be one or more) are used for the usage.
The lines after the separator describe the options.

Each line of options has this format:

------------
<opt-spec><flags>*<arg-hint>? SP+ help LF
------------

`<opt-spec>`::
	its format is the short option character, then the long option name
	separated by a comma. Both parts are not required, though at least one
	is necessary. May not contain any of the `<flags>` characters.
	`h,help`, `dry-run` and `f` are examples of correct `<opt-spec>`.

`<flags>`::
	`<flags>` are of `*`, `=`, `?` or `!`.
	* Use `=` if the option takes an argument.

	* Use `?` to mean that the option takes an optional argument. You
	  probably want to use the `--stuck-long` mode to be able to
	  unambiguously parse the optional argument.

	* Use `*` to mean that this option should not be listed in the usage
	  generated for the `-h` argument. It's shown for `--help-all` as
	  documented in linkgit:gitcli[7].

	* Use `!` to not make the corresponding negated long option available.

`<arg-hint>`::
	`<arg-hint>`, if specified, is used as a name of the argument in the
	help output, for options that take arguments. `<arg-hint>` is
	terminated by the first whitespace.  It is customary to use a
	dash to separate words in a multi-word argument hint.

The remainder of the line, after stripping the spaces, is used
as the help associated with the option.

Blank lines are ignored, and lines that don't match this specification are used
as option group headers

Title: Git Rev-Parse Parseopt Mode and Input Format
Summary
The git rev-parse command's parseopt mode is used for option normalization and parsing, taking a text-based input format with two parts separated by a line containing '--', and allowing for the specification of options with flags, arguments, and help text, enabling standardized option processing for shell scripts.