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
//! # clish
//!
//! The most elegant CLI framework for Rust.
//!
//! Inspired by Typer. Define commands as plain functions. The argument types
//! determine how each parameter is parsed from the command line. Validation,
//! help generation, and error reporting are automatic.
//!
//! ```rust,ignore
//! use clish::prelude::*;
//!
//! #[command]
//! /// Deploy the application
//! fn deploy(target: Pos<String>, env: Named<String>, force: bool) {
//! println!("Deploying {} to {}", target, env);
//! }
//!
//! fn main() {
//! app!().run();
//! }
//! ```
//!
//! # Argument types
//!
//! | Type | Behavior | Example |
//! |-----------------------|---------------------------|---|
//! | [`Pos<T>`] | Positional, required | `myapp cmd foo` |
//! | [`Pos<Option<T>>`] | Positional, optional | `myapp cmd` or `myapp cmd foo` |
//! | [`Pos<Vec<T>>`] | Positional, variadic | `myapp cmd a b c` |
//! | [`Named<T>`] | `--name val`, required | `myapp cmd --env prod` |
//! | [`Named<Option<T>>`] | `--name val`, optional | |
//! | [`Named<Vec<T>>`] | `--name val`, repeatable | `myapp cmd --tag a --tag b` |
//! | `bool` | `--flag` presence | `myapp cmd --force` |
//!
//! `T` must implement [`FromStr`](std::str::FromStr). Type mismatches produce colored errors
//! at runtime. Invalid type combinations (`Option<Vec<T>>`, `Option<bool>`)
//! are rejected at compile time.
//!
//! # Parsing features
//!
//! - `--name=value` and `--name value` forms for named options
//! - `-n value` and `-nvalue` forms with short aliases
//! - Bundled short flags: `-abc` is equivalent to `-a -b -c`
//! - `--` separator: everything after is treated as positional
//! - Environment variable fallback via `param(x, env = "VAR")`
//! - Default values via `param(x, default = "val")`
//! - Value constraints via `param(x, choices = ["a", "b"])`
//! - Mutual exclusion via `param(x, conflicts_with = ["y"])`
//! - Prerequisites via `param(x, requires = ["y"])`
//!
//! # Re-exports
//!
//! This crate re-exports everything you need from `clish-core` and `clish-macros`.
//! See [`prelude`] for a single-use convenience import.
pub use App;
pub use help;
pub use ErrorKind;
pub use ;
pub use command;
pub use inventory;
pub use parse;
pub use CommandEntry;
/// Convenience module for a single `use` import.
///
/// ```rust
/// use clish::prelude::*;
/// ```
///
/// Re-exports: [`App`], [`Flag`], [`Named`], [`Pos`], [`app!`](crate::app),
/// [`command`].
/// Construct an [`App`] with metadata from `Cargo.toml`.
///
/// Reads `CARGO_PKG_NAME`, `CARGO_PKG_VERSION`, and `CARGO_PKG_DESCRIPTION`
/// at compile time. If `CARGO_PKG_DESCRIPTION` is not set, it defaults to
/// an empty string. Override any field with the builder methods on [`App`]:
///
/// ```rust,ignore
/// use clish::prelude::*;
///
/// app!()
/// .name("myapp")
/// .version("1.0.0")
/// .description("Does things.")
/// .details("Longer description shown on --help.")
/// .run();
/// ```
///
/// ## One-shot mode
///
/// Pass a command function to run in one-shot mode (no subcommand dispatch):
///
/// ```rust,ignore
/// use clish::prelude::*;
///
/// #[command]
/// fn main_cmd(target: Pos<String>, verbose: bool) { ... }
///
/// fn main() {
/// app!(main_cmd).run()
/// }
/// ```
///
/// This runs `main_cmd` directly with all arguments. The command must not have
/// custom `name`, `aliases`, `hidden`, or `deprecated` attributes, and no other
/// `#[command]` functions may be registered in the binary. Violations produce
/// a panic at startup.