structopt
Parse command line argument by defining a struct.
0.3.26
87M downloads/mo
#881 most downloaded on crates.io
TeXitoi/structopt
What this package is like to depend on
Last release 5 years ago
no release in 18 months
Release timing varies
gaps range from 2 weeks to 7 months
Most releases are documented
notes for 48 of 55 stable releases
5 versions withdrawn
withdrawn after publishing
10 years old
60 releases · first in 2017
0 releases in the last 12 months
see the full history below
Release timeline
60 releases · Feb 2017 to Jan 2022Releases
latest 60-
0.3.2618 Jan 2022Nothing published for this version
-
0.3.2518 Oct 2021 -
0.3.2418 Oct 2021Nothing published for this version
-
0.3.2330 Aug 2021Release notes
Open source →- Update minimal rust version to 1.46 because of bitflags 1.3
- Fixed a bug that occurs when the type of
mapbecomes ambiguous. - Add support for skip for enum variant subcommands
-
0.3.2204 Jul 2021 -
0.3.2130 Nov 2020Release notes
Open source →- Fixed another breakage
when the struct is placed inside a
macro_rules!macro.
- Fixed another breakage
when the struct is placed inside a
-
0.3.2012 Oct 2020 -
0.3.1908 Oct 2020Release notes
Open source →- Added StructOpt::from_args_safe as a shortcut for
StructOpt::from_iter_safe(std::env::args_os()). - Some links in documentation have been corrected.
- Added StructOpt::from_args_safe as a shortcut for
-
0.3.1823 Sep 2020Release notes
Open source →- Unsafe code has been forbidden. This makes
cargo geigerlist structopt as "safe". Maybe it will help somebody trying to locate a bug in their dependency tree.
- Unsafe code has been forbidden. This makes
-
0.3.1725 Aug 2020Release notes
Open source →- Fixed a breakage with resent rustc versions
due to
quote_spannedmisuse.
- Fixed a breakage with resent rustc versions
due to
-
0.3.1605 Aug 2020Release notes
Open source →- Added the new example.
- Allow
#[structopt(flatten)]fields to have doc comments. The comments are ignored. - The
pawcrate is now being reexported whenpawfeature is enabled, see#407.
-
0.3.1516 Jun 2020Release notes
Open source →- Minor documentation improvements.
- Fixed a latent bug, courtesy of @Aaron1011.
-
0.3.1422 Apr 2020 -
0.3.1308 Apr 2020 -
0.3.1218 Mar 2020 -
0.3.1101 Mar 2020Release notes
Open source →syn's "full" feature is now explicitly enabled. It must have been, but hasn't.
-
0.3.1001 Mar 2020 withdrawn -
0.3.901 Feb 2020 withdrawnRelease notes
Open source →clippywarnings triggered by generated code shall not annoy you anymore! Except for those fromclippy::correctness, these lints are useful even for auto generated code.- Improved error messages.
-
0.3.819 Jan 2020 withdrawnRelease notes
Open source →- You don't have to apply
#[no_version]to everyenumvariant anymore. Just annotate theenumand the setting will be propagated down (#242). - Auto-default.
- External subcommands.
- Flattening subcommands.
- You don't have to apply
-
0.3.728 Dec 2019Release notes
Open source →Nothing's new. Just re-release of
v0.3.6due to the mess with versioning.You may notice that
structopt-derivewas bumped tov0.4.0, that's OK, it's not a breaking change.structoptwill pull the right version in on its on. -
0.3.622 Dec 2019 withdrawnRelease notes
Open source →This is unusually big patch release. It contains a number of bugfixes and new features, some of them may theoretically be considered breaking. We did our best to avoid any problems on user's side but, if it wasn't good enough, please file an issue ASAP.
Bugfixes
-
structoptused to treat::path::to::type::Vec<T>asVec<T>special type. This was considered erroneous. (same forOption<T>andbool). Now only exactVec<T>match is a special type. -
#[structopt(version = expr)]whereexpris not a string literal used to get overridden by auto generated.version()call, incorrectly. Now it doesn't. -
Fixed bug with top-level
App::*calls on multiplestructs, see #289. -
Positional
boolargs with no explicit#[structopt(parse(...))]annotation are now prohibited. This couldn't work well anyway, see this example for details. -
Now we've instituted strict priority between doc comments, about, help, and the like. See the documentation.
HUGE THANKS to
@ssokolowfor tidying up our documentation, teaching me English and explaining why our doc used to suck. I promise I'll make the rest of the doc up to your standards... sometime later!
New features
-
Implement
StructOptforBox<impl StructOpt>so from now on you can useBox<T>withflattenandsubcommand(#304).enum Command { #[structopt(name = "version")] PrintVersion, #[structopt(name = "second")] DoSomething { #[structopt(flatten)] config: Box<DoSomethingConfig>, }, #[structopt(name = "first")] DoSomethingElse { #[structopt(flatten)] config: Box<DoSomethingElseConfig>, } } -
Introduced
#[structopt(verbatim_doc_comment)]attribute that keeps line breaks in doc comments, see the documentation. -
Introduced
#[structopt(rename_all_env)]and#[structopt(env)]magical methods so you can derive env var's name from field's name. See the documentation.
Improvements
-
Now we have nice README for our examples, check it out!
-
Some error messages were improved and clarified, thanks for all people involved!
-
-
0.3.522 Nov 2019Release notes
Open source →try_from_strfunctions are now called with a&strinstead of a&String(#282)
-
0.3.408 Nov 2019 -
0.3.310 Oct 2019Release notes
Open source →- Add
from_flagcustom parser to create flags from non-bool types. Fixes #185
- Add
-
0.3.218 Sep 2019Release notes
Open source →structoptdoes not replace:with,inside "author" strings while inside<...>. Fixes #156- Introduced
#[structopt(skip = expr)]syntax.
-
0.3.106 Sep 2019 -
0.3.030 Aug 2019Release notes
Open source →Breaking changes
Bump minimum rustc version to 1.36 by @TeXitoi
Now
rustc1.36 is the minimum compiler version supported bystructopt, it likely won't work with older compilers.Remove "nightly" feature
Once upon a time this feature had been used to enable some of improvements in
proc-macro2crate that were available only on nightly. Nowadays this feature doesn't mean anything so it's now removed.Support optional vectors of arguments for distinguishing between
-o 1 2,-oand no option provided at all by @sphynx (#180).#[derive(StructOpt)] struct Opt { #[structopt(long)] fruit: Option<Vec<String>>, } fn main() { assert_eq!(Opt::from_args(&["test"]), None); assert_eq!(Opt::from_args(&["test", "--fruit"]), Some(vec![])); assert_eq!(Opt::from_args(&["test", "--fruit=apple orange"]), Some(vec!["apple", "orange"])); }If you need to fall back to the old behavior you can use a type alias:
type Something = Vec<String>; #[derive(StructOpt)] struct Opt { #[structopt(long)] fruit: Option<Something>, }Change default case from 'Verbatim' into 'Kebab' by @0ndorio (#202).
structopt0.3 uses field renaming to deduce a name for long options and subcommands.#[derive(StructOpt)] struct Opt { #[structopt(long)] http_addr: String, // will be renamed to `--http-addr` #[structopt(subcommand)] addr_type: AddrType // this adds `addr-type` subcommand }structopt0.2 used to leave things "as is", not renaming anything. If you want to keep old behavior add#[structopt(rename_all = "verbatim")]on top of astruct/enum.Change
version,authorandaboutattributes behavior.Proposed by @TeXitoi (#217), implemented by @CreepySkeleton (#229).
structopthave been deducingversion,author, andaboutproperties fromCargo.tomlfor a long time (more accurately, fromCARGO_PKG_...environment variables). But many users found this behavior somewhat confusing, and a hack was added to cancel out this behavior:#[structopt(author = "")].In
structopt0.3 this has changed.authorandaboutare no longer deduced by default. You should use#[structopt(author, about)]to explicitly requeststructoptto deduce them.- Contrary,
versionis still deduced by default. You can use#[structopt(no_version)]to cancel it out. #[structopt(author = "", about = "", version = "")]is no longer a valid syntax and will trigger an error.#[structopt(version = "version", author = "author", about = "about")]syntax stays unaffected by this changes.
Raw attributes are removed (#198) by @sphynx
In
structopt0.2 you were able to use any method fromclap::Appandclap::Argvia raw attribute:#[structopt(raw(method_name = "arg"))]. This syntax was kind of awkward.#[derive(StructOpt, Debug)] #[structopt(raw( global_settings = "&[AppSettings::ColoredHelp, AppSettings::VersionlessSubcommands]" ))] struct Opt { #[structopt(short = "l", long = "level", raw(aliases = r#"&["set-level", "lvl"]"#))] level: Vec<String>, }Raw attributes were removed in 0.3. Now you can use any method from
AppandArgdirectly:#[derive(StructOpt)] #[structopt(global_settings(&[AppSettings::ColoredHelp, AppSettings::VersionlessSubcommands]))] struct Opt { #[structopt(short = "l", long = "level", aliases(&["set-level", "lvl"]))] level: Vec<String>, }Improvements
Support skipping struct fields
Proposed by @Morganamilo in (#174) implemented by @sphynx in (#213).
Sometimes you want to include some fields in your
StructOptstructthat are not options andclapshould know nothing about them. Instructopt0.3 it's possible via the#[structopt(skip)]attribute. The field in question will be assigned withDefault::default()value.#[derive(StructOpt)] struct Opt { #[structopt(short, long)] speed: f32, car: String, // this field should not generate any arguments #[structopt(skip)] meta: Vec<u64> }Add optional feature to support
pawby @gameldar (#187)Significantly improve error reporting by @CreepySkeleton (#225)
Now (almost) every error message points to the location it originates from:
error: default_value is meaningless for bool --> $DIR/bool_default_value.rs:14:24 | 14 | #[structopt(short, default_value = true)] | ^^^^^^^^^^^^^ -
0.2.1826 Jun 2019Nothing published for this version
-
0.2.1701 Jun 2019 withdrawnNothing published for this version
-
0.2.1629 May 2019Release notes
Open source →Support optional options with optional argument, allowing
cmd [--opt[=value]]by @sphynx (#188)Sometimes you want to represent an optional option that optionally takes an argument, i.e
[--opt[=value]]. This is represented byOption<Option<T>>#[derive(StructOpt)] struct Opt { #[structopt(long)] fruit: Option<Option<String>>, } fn main() { assert_eq!(Opt::from_args(&["test"]), None); assert_eq!(Opt::from_args(&["test", "--fruit"]), Some(None)); assert_eq!(Opt::from_args(&["test", "--fruit=apple"]), Some("apple")); } -
0.2.1508 Mar 2019 -
0.2.1410 Dec 2018 -
0.2.1301 Nov 2018 -
0.2.1211 Oct 2018 -
0.2.1105 Oct 2018 -
0.2.1007 Jun 2018 -
0.2.905 Jun 2018Release notes
Open source →- Fix a bug when using
flattenby @fbenkstein - Update syn, quote and proc_macro2 by @TeXitoi
- Fix a regression when there is multiple authors by @windwardly
- Fix a bug when using
-
0.2.828 Apr 2018Release notes
Open source →- Add
StructOpt::from_iter_safe(), which returns anErrorinstead of killing the program when it fails to parse, or parses one of the short-circuiting flags. (#98 by @quodlibetor) - Allow users to enable
clapfeatures independently by @Kerollmops - Fix a bug when flattening an enum (#103 by @TeXitoi
- Add
-
0.2.712 Apr 2018Release notes
Open source →- Add flattening, the insertion of options of another StructOpt struct into another (#92) by @birkenfeld
- Fail compilation when using
default_valueorrequiredwithOption(#88) by @Kerollmops
-
0.2.631 Mar 2018 -
0.2.507 Mar 2018Release notes
Open source →- Work around breakage when
proc-macro2's nightly feature is enabled. (#77 and proc-macro2#67) by @fitzgen
- Work around breakage when
-
0.2.425 Feb 2018 -
0.2.316 Feb 2018Release notes
Open source →- An empty line in a doc comment will result in a double linefeed in the generated about/help call by @TeXitoi
-
0.2.212 Feb 2018 -
0.2.111 Feb 2018 -
0.2.010 Feb 2018Release notes
Open source →Breaking changes
Don't special case
u64by @SergioBenitezIf you are using a
u64in your struct to get the number of occurrence of a flag, you should now addparse(from_occurrences)on the flag.For example
#[structopt(short = "v", long = "verbose")] verbose: u64,must be changed by
#[structopt(short = "v", long = "verbose", parse(from_occurrences))] verbose: u64,This feature was surprising as shown in #30. Using the
parsefeature seems much more natural.Change the signature of
Structopt::from_clapto take its argument by reference by @TeXitoiThere was no reason to take the argument by value. Most of the StructOpt users will not be impacted by this change. If you are using
StructOpt::from_clap, just add a&before the argument.Fail if attributes are not used by @TeXitoi
StructOpt was quite fuzzy in its attribute parsing: it was only searching for interesting things, e. g. something like
#[structopt(foo(bar))]was accepted but not used. It now fails the compilation.You should have nothing to do here. This breaking change may highlight some misuse that can be bugs.
In future versions, if there is cases that are not highlighted, they will be considerated as bugs, not breaking changes.
Use
raw()wrapping instead of_rawsuffixing by @TeXitoiThe syntax of raw attributes is changed to improve the syntax.
You have to change
foo_raw = "bar", baz_raw = "foo"byraw(foo = "bar", baz = "foo")orraw(foo = "bar"), raw(baz = "foo").New features
- Add
parse(from_occurrences)parser by @SergioBenitez - Support 1-uple enum variant as subcommand by @TeXitoi
- structopt-derive crate is now an implementation detail, structopt reexport the custom derive macro by @TeXitoi
- Add the
StructOpt::from_itermethod by @Kerollmops
Documentation
Release notes
Open source →Breaking changes
Don't special case
u64by @SergioBenitezIf you are using a
u64in your struct to get the number of occurence of a flag, you should now addparse(from_occurrences)on the flag.For example
#[structopt(short = "v", long = "verbose")] verbose: u64,must be changed by
#[structopt(short = "v", long = "verbose", parse(from_occurrences))] verbose: u64,This feature was surprising as shown in #30. Using the
parsefeature seems much more natural.Change the signature of
Structopt::from_clapto take its argument by reference by @TeXitoiThere was no reason to take the argument by value. Most of the StructOpt users will not be impacted by this change. If you are using
StructOpt::from_clap, just add a&before the argument.Fail if attributes are not used by @TeXitoi
StructOpt was quite fuzzy in its attribute parsing: it was only searching for interresting things, e. g. something like
#[structopt(foo(bar))]was accepted but not used. It now fails the compilation.You should have nothing to do here. This breaking change may highlight some missuse that can be bugs.
In future versions, if there is cases that are not highlighed, they will be considerated as bugs, not breaking changes.
Use
raw()wrapping instead of_rawsuffixing by @TeXitoiThe syntax of raw attributes is changed to improve the syntax.
You have to change
foo_raw = "bar", baz_raw = "foo"byraw(foo = "bar", baz = "foo")orraw(foo = "bar"), raw(baz = "foo").New features
- Add
parse(from_occurrences)parser by @SergioBenitez - Support 1-uple enum variant as subcommand by @TeXitoi
- structopt-derive crate is now an implementation detail, structopt reexport the custom derive macro by @TeXitoi
- Add the
StructOpt::from_itermethod by @Kerollmops
Documentation
- Add
-
0.1.723 Jan 2018 -
0.1.625 Nov 2017 -
0.1.514 Nov 2017 -
0.1.409 Nov 2017 -
0.1.301 Nov 2017 -
0.1.201 Nov 2017 -
0.1.122 Sep 2017 -
0.1.017 Jul 2017 -
0.0.516 Jun 2017 -
0.0.416 Jun 2017Nothing published for this version
-
0.0.311 Feb 2017 -
0.0.210 Feb 2017Nothing published for this version
-
0.0.110 Feb 2017Nothing published for this version
-
0.0.003 Feb 2017Nothing published for this version