StructOpt
Parse command line arguments by defining a struct. It combines clap with custom derive.
Maintenance
As clap v3 is now out, and the structopt features are integrated into (almost as-is), structopt is now in maintenance mode: no new feature will be added.
Bugs will be fixed, and documentation improvements will be accepted.
Documentation
Find it on Docs.rs. You can also check the examples and the changelog.
Example
Add structopt
to your dependencies of your Cargo.toml
:
[]
= "0.3"
And then, in your rust file:
use PathBuf;
use StructOpt;
/// A basic example
Using this example:
$ ./basic
error: The following required arguments were not provided:
--output <output>
USAGE:
basic --output <output> --speed <speed>
For more information try --help
$ ./basic --help
basic 0.3.0
Guillaume Pinot <texitoi@texitoi.eu>, others
A basic example
USAGE:
basic [FLAGS] [OPTIONS] --output <output> [--] [file]...
FLAGS:
-d, --debug Activate debug mode
-h, --help Prints help information
-V, --version Prints version information
-v, --verbose Verbose mode (-v, -vv, -vvv, etc.)
OPTIONS:
-l, --level <level>... admin_level to consider
-c, --nb-cars <nb-cars> Number of cars
-o, --output <output> Output file
-s, --speed <speed> Set speed [default: 42]
ARGS:
<file>... Files to process
$ ./basic -o foo.txt
Opt {
debug: false,
verbose: 0,
speed: 42.0,
output: "foo.txt",
nb_cars: None,
level: [],
files: [],
}
$ ./basic -o foo.txt -dvvvs 1337 -l alice -l bob --nb-cars 4 bar.txt baz.txt
Opt {
debug: true,
verbose: 3,
speed: 1337.0,
output: "foo.txt",
nb_cars: Some(
4,
),
level: [
"alice",
"bob",
],
files: [
"bar.txt",
"baz.txt",
],
}
StructOpt rustc version policy
- Minimum rustc version modification must be specified in the changelog and in the travis configuration.
- Contributors can increment minimum rustc version without any justification if the new version is required by the latest version of one of StructOpt's dependencies (
cargo update
will not fail on StructOpt). - Contributors can increment minimum rustc version if the library user experience is improved.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.