Skip to main content

git_policy_cli/
command_config_table.rs

1//! What:
2//!  The option groups of `git config` in Git 2.56.0,
3//!  one constant per group.
4//! Why:
5//!  Git builds each `git config` subcommand's table from shared groups
6//!      (`CONFIG_LOCATION_OPTIONS`,
7//!  `CONFIG_TYPE_OPTIONS`,
8//!  `CONFIG_DISPLAY_OPTIONS`,
9//!      builtin/config.c:67-117) plus a few rows of its own.
10//!  Keeping the same groups keeps
11//!      one copy of every row.
12//!
13//! In TS you'd write (pseudocode):
14//! ```ts
15//! // export const LOCATION_ROWS: readonly OptionSpec[] = [ ... ];
16//! ```
17
18/// What:
19///  Bring the row type,
20///  its builder,
21///  the arity names and the two tokenizer modes into
22///       this file.
23///  `UNREAD` is the identifier of rows no config fact reads.
24/// Why:
25///   The groups are data for the shared tokenizer.
26///
27/// In TS you'd write (pseudocode):
28/// ```ts
29/// import { Arity, type OptionSpec, row, UNREAD } from './command_options.ts';
30/// ```
31use super::command_options::{Arity, OptionSpec, ParseMode, UNREAD, row};
32
33/// `--global`:
34///  use the per-user configuration file.
35pub const GLOBAL: u16 = 1;
36/// `--system`:
37///  use the system-wide configuration file.
38pub const SYSTEM: u16 = 2;
39/// `-l`,
40///  `--list` of the form without a subcommand word:
41///  list every variable.
42pub const LIST: u16 = 3;
43
44/// What:
45///  `CONFIG_LOCATION_OPTIONS` (builtin/config.c:67-74).
46///  `&[OptionSpec]` is a borrowed
47///       table baked into the program;
48///  `Some(b'f')` is "the byte `f`",
49///  `None` "no letter".
50/// Why:
51///   Every `git config` form starts with these rows;
52///  `--file` and `--blob` take a
53///       value,
54///  so a token after them is never an option.
55///
56/// In TS you'd write (pseudocode):
57/// ```ts
58/// export const LOCATION_ROWS = [row(GLOBAL, undefined, 'global', 'none', true), /* ... */] as const;
59/// ```
60pub const LOCATION_ROWS: &[OptionSpec] = &[
61    row(GLOBAL, None, Some("global"), Arity::None, true),
62    row(SYSTEM, None, Some("system"), Arity::None, true),
63    row(UNREAD, None, Some("local"), Arity::None, true),
64    row(UNREAD, None, Some("worktree"), Arity::None, true),
65    row(UNREAD, Some(b'f'), Some("file"), Arity::Required, true),
66    row(UNREAD, None, Some("blob"), Arity::Required, true),
67];
68
69/// What:
70///  `CONFIG_TYPE_OPTIONS` (builtin/config.c:101-109).
71/// Why:
72///   The six type names are `PARSE_OPT_NOARG | PARSE_OPT_NONEG` (config.c:140-149).
73///
74/// In TS you'd write (pseudocode):
75/// ```ts
76/// export const TYPE_ROWS = [row(UNREAD, 't', 'type', 'required', true), /* ... */] as const;
77/// ```
78pub const TYPE_ROWS: &[OptionSpec] = &[
79    row(UNREAD, Some(b't'), Some("type"), Arity::Required, true),
80    row(UNREAD, None, Some("bool"), Arity::None, false),
81    row(UNREAD, None, Some("int"), Arity::None, false),
82    row(UNREAD, None, Some("bool-or-int"), Arity::None, false),
83    row(UNREAD, None, Some("bool-or-str"), Arity::None, false),
84    row(UNREAD, None, Some("path"), Arity::None, false),
85    row(UNREAD, None, Some("expiry-date"), Arity::None, false),
86];
87
88/// What:
89///  The rows `CONFIG_DISPLAY_OPTIONS` adds before the type rows (config.c:111-117).
90/// Why:
91///   Git appends `CONFIG_TYPE_OPTIONS` to this group,
92///  so users list both in that order.
93///
94/// In TS you'd write (pseudocode):
95/// ```ts
96/// export const DISPLAY_ROWS = [row(UNREAD, 'z', 'null', 'none', true), /* ... */] as const;
97/// ```
98pub const DISPLAY_ROWS: &[OptionSpec] = &[
99    row(UNREAD, Some(b'z'), Some("null"), Arity::None, true),
100    row(UNREAD, None, Some("name-only"), Arity::None, true),
101    row(UNREAD, None, Some("show-origin"), Arity::None, true),
102    row(UNREAD, None, Some("show-scope"), Arity::None, true),
103    row(UNREAD, None, Some("show-names"), Arity::None, true),
104];
105
106/// `git config list`:
107///  the row after the display group (config.c:1043-1050).
108pub const LIST_OTHER_ROWS: &[OptionSpec] =
109    &[row(UNREAD, None, Some("includes"), Arity::None, true)];
110
111/// `git config get`:
112///  the filter rows between location and display (config.c:1084-1089).
113pub const GET_FILTER_ROWS: &[OptionSpec] = &[
114    row(UNREAD, None, Some("all"), Arity::None, true),
115    row(UNREAD, None, Some("regexp"), Arity::None, true),
116    row(UNREAD, None, Some("value"), Arity::Required, true),
117    row(UNREAD, None, Some("fixed-value"), Arity::None, true),
118    row(UNREAD, None, Some("url"), Arity::Required, true),
119];
120
121/// `git config get`:
122///  the rows after the display group (config.c:1091-1095).
123pub const GET_OTHER_ROWS: &[OptionSpec] = &[
124    row(UNREAD, None, Some("includes"), Arity::None, true),
125    row(UNREAD, None, Some("default"), Arity::Required, true),
126];
127
128/// `git config set`:
129///  the rows after location and type (config.c:1142-1148).
130pub const SET_ROWS: &[OptionSpec] = &[
131    row(UNREAD, None, Some("all"), Arity::None, true),
132    row(UNREAD, None, Some("value"), Arity::Required, true),
133    row(UNREAD, None, Some("fixed-value"), Arity::None, true),
134    row(UNREAD, None, Some("comment"), Arity::Required, true),
135    row(UNREAD, None, Some("append"), Arity::None, true),
136];
137
138/// `git config unset`:
139///  the rows after location (config.c:1201-1204).
140pub const UNSET_ROWS: &[OptionSpec] = &[
141    row(UNREAD, None, Some("all"), Arity::None, true),
142    row(UNREAD, None, Some("value"), Arity::Required, true),
143    row(UNREAD, None, Some("fixed-value"), Arity::None, true),
144];
145
146/// What:
147///  The action rows of the form without a subcommand word (config.c:1373-1387).
148/// Why:
149///   Each is an `OPT_CMDMODE`,
150///  which takes no value and has no `--no-` form.
151///
152/// In TS you'd write (pseudocode):
153/// ```ts
154/// export const LEGACY_ACTION_ROWS = [row(UNREAD, undefined, 'get', 'none', false), /* ... */] as const;
155/// ```
156pub const LEGACY_ACTION_ROWS: &[OptionSpec] = &[
157    row(UNREAD, None, Some("get"), Arity::None, false),
158    row(UNREAD, None, Some("get-all"), Arity::None, false),
159    row(UNREAD, None, Some("get-regexp"), Arity::None, false),
160    row(UNREAD, None, Some("get-urlmatch"), Arity::None, false),
161    row(UNREAD, None, Some("replace-all"), Arity::None, false),
162    row(UNREAD, None, Some("add"), Arity::None, false),
163    row(UNREAD, None, Some("unset"), Arity::None, false),
164    row(UNREAD, None, Some("unset-all"), Arity::None, false),
165    row(UNREAD, None, Some("rename-section"), Arity::None, false),
166    row(UNREAD, None, Some("remove-section"), Arity::None, false),
167    row(LIST, Some(b'l'), Some("list"), Arity::None, false),
168    row(UNREAD, Some(b'e'), Some("edit"), Arity::None, false),
169    row(UNREAD, None, Some("get-color"), Arity::None, false),
170    row(UNREAD, None, Some("get-colorbool"), Arity::None, false),
171];
172
173/// The form without a subcommand word:
174///  the rows after the display group (config.c:1389-1395).
175pub const LEGACY_OTHER_ROWS: &[OptionSpec] = &[
176    row(UNREAD, None, Some("default"), Arity::Required, true),
177    row(UNREAD, None, Some("comment"), Arity::Required, true),
178    row(UNREAD, None, Some("fixed-value"), Arity::None, true),
179    row(UNREAD, None, Some("includes"), Arity::None, true),
180];
181
182/// `PARSE_OPT_STOP_AT_NON_OPTION`:
183///  every form except `list` and `edit` stops reading
184/// options at the first name (config.c:1100-1101,
185///  1155-1156,
186///  1209-1210,
187///  1241-1242,
188/// 1271-1272,
189///  1403-1405).
190pub const CONFIG_STOP_MODE: ParseMode = ParseMode {
191    keep_unknown: false,
192    stop_at_non_option: true,
193};