Skip to main content

Module command_options

Module command_options 

Source
Expand description

Git 2.56.0 parse-options tokenization of one command’s argument region. What: Read one Git command’s arguments the way Git 2.56.0 parse-options.c reads them. Why: A policy that guesses which token is an option, a value or a path can be bypassed by a spelling Git accepts. Every per-command module declares Git’s own option table and this module walks the arguments exactly once with Git’s rules.

In TS you’d write (pseudocode):

// parseOptions({ args, table, mode, wrapperFlags }): ParsedOptions  (throws OptionError)

Structs§

Occurrence
What: One accepted use of a declared option. Why: Git lets the last use win, so order and negation are kept for the command module.
OptionError
What: One refusal, with the index of the token that caused it. Why: A diagnostic can name the exact argument without this module rendering text for it.
OptionSpec
What: struct OptionSpec is one row of a Git option table. u16 is an unsigned 16-bit integer (siblings: u8, u32, usize). Option<u8> is “a byte or nothing”; &'static str is text baked into the program. Why: id lets a command module ask about an option by a named constant instead of by table position. u16 (not usize) keeps rows small; no table has 65 thousand rows.
ParseMode
What: Per-call switches matching Git’s enum parse_opt_flags. bool is true or false. Why: git stash keeps unknown options and stops at the first non-option; most commands do neither. PARSE_OPT_KEEP_DASHDASH needs no switch: the -- index is always reported.
ParsedOptions
What: Everything learned from one argument region. Vec<T> is an owned, growable list (siblings: &[T], a borrowed view, and [T; N], a fixed-size array). Why: The result outlives the scan and its lengths are unknown beforehand, so it owns lists.
WrapperOccurrence
What: One wrapper-only flag found where Git would have looked for an option. Why: Only such positions may be removed before forwarding; values and paths stay.

Enums§

Arity
What: enum Arity lists how an option relates to a value. An enum is a closed set of named alternatives. #[derive(...)] asks the compiler to generate copying (Clone, Copy), debug printing (Debug) and == (Eq, PartialEq). Why: Value consumption decides whether the next token is a path or an option value.
Boundary
What: How option parsing ended; each variant holds the index of the ending token. Why: Tokens after the boundary are never options, and commands treat -- specially.
OptionErrorKind
What: Why Git would refuse the region before running the command. Why: The caller reports or forwards such a command line; it must never guess its facts.
OptionValue
What: Where an option’s value sits. usize is the index type of lists (siblings: u32, u64); every standard list API indexes with usize. Why: A value is reported by position, never copied, so its bytes stay exactly as given.

Constants§

DEFAULT_MODE
Flags 0, the mode of commit, add, push, clean, branch and status.
UNREAD
Identifier of every row no command fact reads; such rows only supply arity.

Functions§

parse_options
What: Tokenize one region in a single forward pass (parse_options_step, parse-options.c:995-1169). Result<A, B> is “either success A or failure B”. Why: One faithful scan replaces per-command guesses about option arity. Gotcha: Indexes in the result are relative to arguments, the region after the subcommand.
row
What: const fn is a function the compiler can run while building a const table. Why: One short call per row keeps each Git table readable beside the C source.