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
//! # cli-command
//!
//! A lightweight and ergonomic command-line argument parser for Rust applications.
//!
//! ## Features
//!
//! - ๐ **Minimal dependencies** - Only 3 lightweight dependencies for macro support
//! - ๐ฏ **Dual API design** - Both method-based and macro-based interfaces
//! - ๐ง **Flexible parsing** - Supports both `-` and `--` argument prefixes
//! - ๐ **Type conversion** - Built-in support for common types
//! - โก **Error handling** - Comprehensive error types with helpful messages
//! - ๐งช **Well tested** - Extensive test coverage
//! - ๐จ **Macro ergonomics** - `cli_args!` macro for boilerplate-free argument extraction
//! - ๐ญ **Command matching** - `cli_match!` macro for clean command routing
//!
//! ## Quick Start
//!
//! ```rust
//! use cli_command::{parse_command_line, Command};
//!
//! fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Parse command line arguments
//! let cmd = parse_command_line().unwrap();
//!
//! // Get a simple argument
//! if let Some(port) = cmd.get_argument("port") {
//! println!("Port: {}", port);
//! }
//!
//! // Get a required argument with type conversion
//! let threads: usize = cmd.get_argument_or_default("threads", 4).unwrap();
//! println!("Threads: {}", threads);
//!
//! // Get argument with default value
//! let timeout: u64 = cmd.get_argument_or_default("timeout", 30).unwrap();
//! println!("Timeout: {}", timeout);
//!
//! Ok(())
//! }
//! ```
//!
//! ## Examples
//!
//! See the `examples/` directory for complete working examples:
//! - `simple_server.rs` - A web server with configuration options
//! - `file_processor.rs` - A file processing tool with multiple subcommands
//!
//! ## Error Handling
//!
//! The crate provides comprehensive error handling with helpful error messages:
//!
//! ```rust
//! use cli_command::{CliError, CliErrorKind};
//!
//! use cli_command::parse_command_string;
//! let cmd = parse_command_string("--required_arg value").unwrap();
//! match cmd.get_argument_mandatory("required_arg") {
//! Ok(value) => println!("Got: {}", value),
//! Err(CliError { kind: CliErrorKind::MissingArgument(arg), .. }) => {
//! eprintln!("Missing required argument: {}", arg);
//! }
//! Err(e) => eprintln!("Error: {}", e),
//! }
//! ```
pub use ;
pub use Command;
pub use ;
/// Argument extraction macro
///
/// This macro provides a convenient way to extract command-line arguments
/// with default values in a single expression. It automatically parses the
/// command line, so you don't need to call `parse_command_line()` yourself.
///
/// # Syntax
///
/// ```rust
/// use cli_command::cli_args;
///
/// fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let (port, host, verbose) = cli_args!(
/// port: u16 = 8080,
/// host: String = "localhost".to_string(),
/// verbose: bool = false
/// );
/// Ok(())
/// }
/// ```
///
/// # Examples
///
/// ```rust
/// use cli_command::cli_args;
///
/// fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let (port, host, workers, verbose) = cli_args!(
/// port: u16 = 8080,
/// host: String = "localhost".to_string(),
/// workers: usize = 4,
/// verbose: bool = false
/// );
///
/// println!("Server: {}:{} (workers: {}, verbose: {})", host, port, workers, verbose);
/// Ok(())
/// }
/// ```
/// Command matching macro
///
/// This macro provides a convenient way to match command names and automatically
/// parse the command line. It eliminates the need to manually call `parse_command_line()`.
///
/// # Syntax
///
/// ```rust
/// use cli_command::cli_match;
///
/// fn main() -> Result<(), Box<dyn std::error::Error>> {
/// cli_match! {
/// "command1" => { /* handle command1 */ Ok(()) },
/// "command2" => { /* handle command2 */ Ok(()) },
/// _ => { /* handle unknown commands */ Ok(()) }
/// }
/// }
/// ```
///
/// # Examples
///
/// ```rust
/// use cli_command::{cli_match, cli_args};
///
/// fn start_server(port: u16, host: String) -> Result<(), Box<dyn std::error::Error>> {
/// println!("Starting server on {}:{}", host, port);
/// Ok(())
/// }
///
/// fn build_project(output: String, release: bool) -> Result<(), Box<dyn std::error::Error>> {
/// println!("Building project to {} (release: {})", output, release);
/// Ok(())
/// }
///
/// fn print_help() -> Result<(), Box<dyn std::error::Error>> {
/// println!("Available commands: serve, build, help");
/// Ok(())
/// }
///
/// fn main() -> Result<(), Box<dyn std::error::Error>> {
/// cli_match! {
/// "serve" => {
/// let (port, host) = cli_args!(
/// port: u16 = 8080,
/// host: String = "localhost".to_string()
/// );
/// start_server(port, host)
/// },
/// "build" => {
/// let (output, release) = cli_args!(
/// output: String = "dist".to_string(),
/// release: bool = false
/// );
/// build_project(output, release)
/// },
/// "help" => print_help(),
/// _ => {
/// eprintln!("Unknown command");
/// print_help();
/// Ok(())
/// }
/// }
/// }
/// ```