1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
//! *Prototype of a command line argument parser with several opposite design goals from [clap].*
//!
//! [clap]: https://github.com/clap-rs/clap
//!
//! > ⚠️ This project is in alpha stage and is not ready for production yet.
//! > The API is subject to change. Feedbacks are welcome.
//!
//! See [repository README](https://github.com/oxalica/palc?tab=readme-ov-file#palc) for details.
//!
//! TODO: Documentations.
use ;
use ErrorKind;
use ;
pub use crateError;
pub type Result<T, E = Error> = Result;
/// Not public API. Only for proc-macro internal use.
// To scan all usages:
// ```sh
// rg --only-matching --no-filename '\b__rt::\w+' | LC_COLLATE=C sort --unique
// ```
/// Top-level command interface.
///
/// You should only get an implementation via [`derive(Parser)`](macro@Parser).
/// Do not manually implement this trait.
/// Derive macro generating top-level [`Parser`][trait@Parser] implementation.
///
/// This macro currently only accepts non-generic `struct`s, and is
/// a superset of [`Args`][macro@Args].
/// `derive(Args)` must *NOT* be used if there is already `derive(Parser)`.
///
/// All attributes supported on the struct are identical to [`Args`][macro@Args].
pub use Parser;
/// Derive macro for a composable collection of CLI arguments.
///
/// *Note: Currently only this derive-macro is part of public API, but the
/// trait `Args` is not.*
///
/// This macro only accepts non-generic `struct`s. The type deriving this macro
/// can be used by other types via `#[command(flatten)]`.
///
/// # Container attributes
///
/// These subcommand-level attributes on `struct` are the description of the
/// subcommand itself. They are only meaningful on top-level [`Parser`], or a
/// struct used in [`Subcommand`] enum's tuple variant. If this struct is used
/// as `#[command(flatten)]`, these container attributes are useless and ignored.
///
/// - `#[command(name = "...")]`
///
/// TODO: TBD
///
/// - `#[command(version)]` or `#[command(version = EXPR)]`
///
/// TODO: TBD
///
/// - `#[command(long_about = CONST_EXPR)]` or `#[command(long_about)]`
///
/// Override the default "about" text shown in the generated help output.
///
/// `CONST_EXPR`, if present, must be valid in const-context and has type
/// `&'static str`.
///
/// If no explicit value (`= CONST_EXPR`) is set, package description from
/// `Cargo.toml` is used as its value.
/// If this attribute is not present, the doc-comment of the struct is used
/// as its value.
///
/// - `#[command(after_long_about = CONST_EXPR)]`
///
/// `CONST_EXPR`, if present, must be valid in const-context and has type
/// `&'static str`.
///
/// Additional text to be printed after the generated help output.
///
/// - `#[doc = "..."]` or `/// ...`
///
/// The default value for `long_about` if that attribute is not present.
///
/// # Field attributes for composition
///
/// - `#[command(flatten)]`
///
/// Flatten (inline) a collection of arguments into this struct.
///
/// The field type must derive [`Args`], must not contains a subcommand field,
/// and must not form a dependency cycle, otherwise a compile error is
/// emitted.
///
/// - Named arguments
///
/// Since named arguments are unordered, flattened arguments and
/// non-flattened ones can be parsed in any interleaving order.
///
/// In a struct, all named arguments, including flattened ones, should *NOT*
/// have collide names. Otherwise, the behavior is unspecified but
/// deterministic, and may change in the future.
/// The current behavior is: only one argument "wins" and consumes the value.
///
/// - Unnamed arguments
///
/// TODO: Not yet supported to be flattened.
///
/// - `#[command(subcommand)]`
///
/// Define a subcommand. At most one field can be marked as subcommand.
/// The field type must be either `SubcmdType` or `Option<SubcmdType>` where
/// `SubcmdType` derives [`Subcommand`].
///
/// # Field attributes for arguments
///
/// TODO
pub use Args;
/// Derive macro for a composable enum of CLI subcommands.
///
/// *Note: Currently only this derive-macro is part of public API, but the
/// trait `Subcommand` is not.*
///
/// This macro supports non-generic `enum`s.
///
/// # Subcommand names
///
/// Each variant corresponds to a subcommand with the name being the variant
/// identifier converted to "kebab-case".
/// Duplicated names after case conversion produce a compile error.
///
/// # Supported variants
///
/// - `UnitVariant`
///
/// A subcommand with no arguments on its own. Additional
/// arguments may still be accepted after it, if there is any from ancestor
/// subcommands.
///
/// [`#[command(..)]` container attributes][command_attrs] are allowed on this variant.
///
/// - `StructVariant { .. }`
///
/// An inlined subcommand. Variant fields are handled in
/// the same way as fields of [`derive(Args)`][Args]. See its docs for details.
///
/// [`#[command(..)]` container attributes][command_attrs] are allowed on this variant.
///
/// - `TupleVariant(AnotherType)`
///
/// An outlined subcommand where `AnotherType` must derive [`Args`].
///
/// [`#[command(..)]` container attributes][command_attrs] are *NOT* allowed on this variant.
/// Instead, those on `AnotherType` are used.
///
/// - Other kinds of variant are rejected.
///
/// [command_attrs]: derive.Args.html#container-attributes
pub use Subcommand;
/// Derive macro for enums parsable from argument values.
///
/// *Note: Currently only this derive-macro is part of public API, but the
/// trait `ValueEnum` is not.*
///
/// # Container attributes
///
/// - `#[value(rename_all = "...")]`
///
/// Override the variant name case conversion.
/// When not present, the default value is `"kebab-case"`.
///
/// All supported conversions:
/// - `"camelCase"`
/// - `"kebab-case"`
/// - `"PascalCase"`
/// - `"SCREAMING_SNAKE_CASE"`
/// - `"snake_case"`
/// - `"lower"`
/// - `"UPPER"`
/// - `"verbatim"`
///
/// # Variant attributes
///
/// - `#[value(name = "...")]`
///
/// Override the default case-converted name for this variant.
/// The string literal is taken verbatim for parsing, but it is still
/// checked for forbiddgen characters and conflicts. See the next section.
///
/// If not present, the variant name after case conversion (see previous section).
///
/// # Errors
///
/// - ASCII control characters are forbidden from subcommand names, due to
/// implementation limitations. A compile error is emitted if any is found.
///
/// - The macro will check all variant names for parsing (after case conversion if
/// necessary) do not collide. Otherwise a compile error is emitted.
pub use ValueEnum;