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
// SPDX-License-Identifier: EUPL-1.2
//! pound: a low footprint, derive-first cli parser.
//!
//! the derive emits a flat `&'static` [`spec::CommandSpec`] and one non-generic
//! engine interprets it, so derives stay ergonomic while adding almost nothing
//! to the binary and nothing at runtime.
//!
//! field shapes carry meaning, so most fields need no attribute:
//!
//! | shape | meaning |
//! |-------------|----------------------|
//! | `bool` | flag, presence is true |
//! | `T` | required positional |
//! | `Option<T>` | optional positional |
//! | `Vec<T>` | variadic/repeatable |
//!
//! `#[pound(short)]` / `#[pound(long)]` promote any of these to a named option.
//! the annotated thing is the switch, values stay bare.
//!
//! ```ignore
//! use pound::Parse;
//!
//! #[derive(Parse)]
//! struct Add {
//! name: String, // required positional
//! url: String, // required positional
//! #[pound(long)] unpack: Option<String>,
//! #[pound(long)] follows: Vec<String>, // repeatable --follows
//! #[pound(short, long)] force: bool, // -f / --force
//! }
//!
//! let add = Add::parse(); // exits on -h/--help or a parse error
//! ```
//!
//! you can also hand-build a [`spec::CommandSpec`] and impl [`Parse`] yourself,
//! as the test suite does.
extern crate alloc;
/// the `alloc` items the modules lean on, in one place. populated only under
/// `no_std` (the `std` prelude already provides them), so every module can
/// `use crate::alloc_prelude::*` without repeating `cfg`-gated import lists —
/// and adding a `String`/`format!`/`Vec` anywhere just works in both builds.
pub use Error;
pub use Matches;
pub use ;
pub use ;
// the derive macros share names with the `Parse` trait and `FromArg`, which is
// fine: macros and types live in separate namespaces (same trick serde uses).
pub use ;
/// the trait the derive targets, also implementable by hand.
///
/// a type carries its static [`CommandSpec`] and reads itself out of
/// [`Matches`]. [`Self::parse`] is the common "parse argv or exit" path, the
/// `try_*` variants hand back the [`Error`] (including the [`Error::Help`] /
/// [`Error::Version`] signals).
/// build a borrowed argument iterator from a raw libc `main(argc, argv)`.
///
/// for a `#![no_std]` program that owns its entry point: pairs with
/// [`Parse::try_parse_from`] once you `skip(1)` the program name.
///
/// the yielded `&str`s borrow directly from `argv` — no allocation — and any
/// non-UTF-8 argument is skipped. pound cannot *source* argv portably (that is
/// the OS boundary `std` exists to cross), but it can bridge the pointers you
/// already hold.
///
/// ```no_run
/// use core::ffi::{c_char, c_int};
///
/// // call this from your `#![no_main]` libc entry point, forwarding its args:
/// fn run(argc: c_int, argv: *const *const c_char) {
/// // SAFETY: argc/argv are the unmodified parameters libc passed `main`.
/// let args = unsafe { pound::args_from_raw(argc, argv) }.skip(1);
/// // let cmd = MyCommand::try_parse_from(args)?;
/// let _ = args.count();
/// }
/// ```
///
/// # Safety
///
/// `argv` must point to `argc` consecutive, valid, NUL-terminated C strings
/// that stay alive and immutable for `'a` — exactly the contract a libc runtime
/// upholds for `main`'s parameters. A negative `argc` is treated as zero.
// argc/argv are the libc contract names; keeping them reads clearer than any
// rename clippy's `similar_names` would prefer.
pub unsafe