Skip to main content

git_policy_cli/
command_stash_table.rs

1//! What:
2//!  The option tables of every `git stash` subcommand in Git 2.56.0.
3//! Why:
4//!  `git stash` dispatches to subcommands that each parse their own options with their
5//!      own flags (builtin/stash.c);
6//!  whether a token is an option value depends on which
7//!      subcommand reads it.
8//!
9//! In TS you'd write (pseudocode):
10//! ```ts
11//! // export const STASH_PUSH_TABLE: readonly OptionSpec[] = [ ... ];
12//! ```
13
14/// What:
15///  Bring the row type,
16///  its builder,
17///  the arity names and the parse-mode type into
18///       this file.
19///  `UNREAD` is the identifier of rows no stash fact reads.
20/// Why:
21///   The tables are data for the shared tokenizer.
22///
23/// In TS you'd write (pseudocode):
24/// ```ts
25/// import { Arity, type OptionSpec, type ParseMode, row, UNREAD } from './command_options.ts';
26/// ```
27use super::command_options::{Arity, OptionSpec, ParseMode, UNREAD, row};
28
29/// `git stash push` (`push_stash`,
30///  builtin/stash.c:1920-1940).
31pub const STASH_PUSH_TABLE: &[OptionSpec] = &[
32    row(UNREAD, Some(b'k'), Some("keep-index"), Arity::None, true),
33    row(UNREAD, Some(b'S'), Some("staged"), Arity::None, true),
34    row(UNREAD, Some(b'p'), Some("patch"), Arity::None, true),
35    row(UNREAD, None, Some("auto-advance"), Arity::None, true),
36    row(UNREAD, Some(b'U'), Some("unified"), Arity::Required, false),
37    row(
38        UNREAD,
39        None,
40        Some("inter-hunk-context"),
41        Arity::Required,
42        false,
43    ),
44    row(UNREAD, Some(b'q'), Some("quiet"), Arity::None, true),
45    row(
46        UNREAD,
47        Some(b'u'),
48        Some("include-untracked"),
49        Arity::None,
50        true,
51    ),
52    row(UNREAD, Some(b'a'), Some("all"), Arity::None, true),
53    row(UNREAD, Some(b'm'), Some("message"), Arity::Required, true),
54    row(
55        UNREAD,
56        None,
57        Some("pathspec-from-file"),
58        Arity::Required,
59        true,
60    ),
61    row(UNREAD, None, Some("pathspec-file-nul"), Arity::None, true),
62];
63
64/// `git stash save` (`save_stash`,
65///  builtin/stash.c:2027-2045):
66///  `push` without the pathspec
67/// file options.
68pub const STASH_SAVE_TABLE: &[OptionSpec] = &[
69    row(UNREAD, Some(b'k'), Some("keep-index"), Arity::None, true),
70    row(UNREAD, Some(b'S'), Some("staged"), Arity::None, true),
71    row(UNREAD, Some(b'p'), Some("patch"), Arity::None, true),
72    row(UNREAD, None, Some("auto-advance"), Arity::None, true),
73    row(UNREAD, Some(b'U'), Some("unified"), Arity::Required, false),
74    row(
75        UNREAD,
76        None,
77        Some("inter-hunk-context"),
78        Arity::Required,
79        false,
80    ),
81    row(UNREAD, Some(b'q'), Some("quiet"), Arity::None, true),
82    row(
83        UNREAD,
84        Some(b'u'),
85        Some("include-untracked"),
86        Arity::None,
87        true,
88    ),
89    row(UNREAD, Some(b'a'), Some("all"), Arity::None, true),
90    row(UNREAD, Some(b'm'), Some("message"), Arity::Required, true),
91];
92
93/// `git stash apply` (`apply_stash`,
94///  builtin/stash.c:783-793).
95pub const STASH_APPLY_TABLE: &[OptionSpec] = &[
96    row(UNREAD, Some(b'q'), Some("quiet"), Arity::None, true),
97    row(UNREAD, None, Some("index"), Arity::None, true),
98    row(UNREAD, None, Some("label-ours"), Arity::Required, true),
99    row(UNREAD, None, Some("label-theirs"), Arity::Required, true),
100    row(UNREAD, None, Some("label-base"), Arity::Required, true),
101];
102
103/// `git stash pop` (`pop_stash`,
104///  builtin/stash.c:889-893).
105pub const STASH_POP_TABLE: &[OptionSpec] = &[
106    row(UNREAD, Some(b'q'), Some("quiet"), Arity::None, true),
107    row(UNREAD, None, Some("index"), Arity::None, true),
108];
109
110/// `git stash drop` (`drop_stash`,
111///  builtin/stash.c:865-867).
112pub const STASH_DROP_TABLE: &[OptionSpec] =
113    &[row(UNREAD, Some(b'q'), Some("quiet"), Arity::None, true)];
114
115/// `git stash store` (`store_stash`,
116///  builtin/stash.c:1162-1166).
117pub const STASH_STORE_TABLE: &[OptionSpec] = &[
118    row(UNREAD, Some(b'q'), Some("quiet"), Arity::None, true),
119    row(UNREAD, Some(b'm'), Some("message"), Arity::Required, true),
120];
121
122/// `git stash show` (`show_stash`,
123///  builtin/stash.c:1041-1048).
124pub const STASH_SHOW_TABLE: &[OptionSpec] = &[
125    row(
126        UNREAD,
127        Some(b'u'),
128        Some("include-untracked"),
129        Arity::None,
130        true,
131    ),
132    row(UNREAD, None, Some("only-untracked"), Arity::None, false),
133];
134
135/// `git stash export` (`export_stash`,
136///  builtin/stash.c:2434-2440).
137pub const STASH_EXPORT_TABLE: &[OptionSpec] = &[
138    row(UNREAD, None, Some("print"), Arity::None, false),
139    row(UNREAD, None, Some("to-ref"), Arity::Required, true),
140];
141
142/// `git stash clear`,
143///  `branch`,
144///  `list` and `import` declare no options.
145pub const STASH_EMPTY_TABLE: &[OptionSpec] = &[];
146
147/// Flags `0` or only `PARSE_OPT_KEEP_DASHDASH`:
148///  `push`,
149///  `save`,
150///  `apply`,
151///  `pop`,
152///  `drop`,
153/// `branch`,
154///  `export` and `import`.
155pub const STASH_PLAIN_MODE: ParseMode = ParseMode {
156    keep_unknown: false,
157    stop_at_non_option: false,
158};
159
160/// `PARSE_OPT_KEEP_UNKNOWN_OPT`:
161///  `list`,
162///  `show` and `store` forward unknown options.
163pub const STASH_KEEP_UNKNOWN_MODE: ParseMode = ParseMode {
164    keep_unknown: true,
165    stop_at_non_option: false,
166};
167
168/// `PARSE_OPT_STOP_AT_NON_OPTION`:
169///  `clear`,
170///  and `push` when no subcommand was written
171/// (builtin/stash.c:1945-1948).
172pub const STASH_STOP_MODE: ParseMode = ParseMode {
173    keep_unknown: false,
174    stop_at_non_option: true,
175};