Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V0.3.7 #316

Merged
merged 2 commits into from
Dec 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# v0.3.6 (2019-12-22)
# v0.3.7 (2019-12-28)

Nothing's new. Just re-release of `v0.3.6` due to
[the mess with versioning](https://github.com/TeXitoi/structopt/issues/315#issuecomment-568502792).

You may notice that `structopt-derive` was bumped to `v0.4.0`, that's OK, it's not a breaking change.
`structopt` will pull the right version in on its on.

# v0.3.6 (2019-12-22) - YANKED

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
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "structopt"
version = "0.3.6"
version = "0.3.7"
edition = "2018"
authors = ["Guillaume Pinot <[email protected]>", "others"]
description = "Parse command line argument by defining a struct."
Expand Down Expand Up @@ -28,7 +28,7 @@ travis-ci = { repository = "TeXitoi/structopt" }

[dependencies]
clap = { version = "2.33", default-features = false }
structopt-derive = { path = "structopt-derive", version = "0.3.6" }
structopt-derive = { path = "structopt-derive", version = "=0.4.0" }

[dev-dependencies]
trybuild = "1.0.5"
Expand Down
37 changes: 18 additions & 19 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -966,27 +966,24 @@ pub trait StructOpt {
{
Ok(Self::from_clap(&Self::clap().get_matches_from_safe(iter)?))
}
}

// All the following is NOT PUBLIC API!!!
//
// ** SUBJECT TO CHANGE WITHOUT NOTICE!!! **

#[doc(hidden)]
fn is_subcommand() -> bool {
unimplemented!()
/// This trait is NOT API. **SUBJECT TO CHANGE WITHOUT NOTICE!**.
#[doc(hidden)]
pub trait StructOptInternal: StructOpt {
fn augment_clap<'a, 'b>(app: clap::App<'a, 'b>) -> clap::App<'a, 'b> {
app
}

#[doc(hidden)]
fn augment_clap<'a, 'b>(_app: clap::App<'a, 'b>) -> clap::App<'a, 'b> {
unimplemented!()
fn is_subcommand() -> bool {
false
}

#[doc(hidden)]
fn from_subcommand<'a, 'b>(_sub: (&'b str, Option<&'b clap::ArgMatches<'a>>)) -> Option<Self>
where
Self: Sized,
Self: std::marker::Sized,
{
unimplemented!()
None
}
}

Expand All @@ -998,19 +995,21 @@ impl<T: StructOpt> StructOpt for Box<T> {
fn from_clap(matches: &clap::ArgMatches<'_>) -> Self {
Box::new(<T as StructOpt>::from_clap(matches))
}
}

impl<T: StructOptInternal> StructOptInternal for Box<T> {
#[doc(hidden)]
fn augment_clap<'a, 'b>(app: clap::App<'a, 'b>) -> clap::App<'a, 'b> {
<T as StructOpt>::augment_clap(app)
fn is_subcommand() -> bool {
<T as StructOptInternal>::is_subcommand()
}

#[doc(hidden)]
fn is_subcommand() -> bool {
<T as StructOpt>::is_subcommand()
fn from_subcommand<'a, 'b>(sub: (&'b str, Option<&'b clap::ArgMatches<'a>>)) -> Option<Self> {
<T as StructOptInternal>::from_subcommand(sub).map(Box::new)
}

#[doc(hidden)]
fn from_subcommand<'a, 'b>(sub: (&'b str, Option<&'b clap::ArgMatches<'a>>)) -> Option<Self> {
<T as StructOpt>::from_subcommand(sub).map(Box::new)
fn augment_clap<'a, 'b>(app: clap::App<'a, 'b>) -> clap::App<'a, 'b> {
<T as StructOptInternal>::augment_clap(app)
}
}
2 changes: 1 addition & 1 deletion structopt-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "structopt-derive"
version = "0.3.6"
version = "0.4.0"
edition = "2018"
authors = ["Guillaume Pinot <[email protected]>"]
description = "Parse command line argument by defining a struct, derive crate."
Expand Down
38 changes: 28 additions & 10 deletions structopt-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ fn gen_augmentation(

let span = field.span();
let ts = quote! {
let #app_var = <#subcmd_type as ::structopt::StructOpt>::augment_clap( #app_var );
let #app_var = <#subcmd_type as ::structopt::StructOptInternal>::augment_clap(
#app_var
);
#required
};
Some((span, ts))
Expand Down Expand Up @@ -116,8 +118,8 @@ fn gen_augmentation(
Kind::FlattenStruct => {
let ty = &field.ty;
Some(quote_spanned! { kind.span()=>
let #app_var = <#ty as ::structopt::StructOpt>::augment_clap(#app_var);
let #app_var = if <#ty as ::structopt::StructOpt>::is_subcommand() {
let #app_var = <#ty as ::structopt::StructOptInternal>::augment_clap(#app_var);
let #app_var = if <#ty as ::structopt::StructOptInternal>::is_subcommand() {
#app_var.setting(::structopt::clap::AppSettings::SubcommandRequiredElseHelp)
} else {
#app_var
Expand Down Expand Up @@ -249,7 +251,7 @@ fn gen_constructor(fields: &Punctuated<Field, Comma>, parent_attribute: &Attrs)
_ => quote_spanned!( ty.span()=> .unwrap() ),
};
quote_spanned! { kind.span()=>
#field_name: <#subcmd_type as ::structopt::StructOpt>::from_subcommand(
#field_name: <#subcmd_type as ::structopt::StructOptInternal>::from_subcommand(
matches.subcommand())
#unwrapper
}
Expand Down Expand Up @@ -396,7 +398,7 @@ fn gen_clap_struct(struct_attrs: &[Attribute]) -> GenOutput {
let augmented_tokens = quote! {
fn clap<'a, 'b>() -> ::structopt::clap::App<'a, 'b> {
let app = #clap_tokens;
<Self as ::structopt::StructOpt>::augment_clap(app)
<Self as ::structopt::StructOptInternal>::augment_clap(app)
}
};

Expand Down Expand Up @@ -426,7 +428,7 @@ fn gen_clap_enum(enum_attrs: &[Attribute]) -> GenOutput {
fn clap<'a, 'b>() -> ::structopt::clap::App<'a, 'b> {
let app = #clap_tokens
.setting(::structopt::clap::AppSettings::SubcommandRequiredElseHelp);
<Self as ::structopt::StructOpt>::augment_clap(app)
<Self as ::structopt::StructOptInternal>::augment_clap(app)
}
};

Expand Down Expand Up @@ -458,8 +460,10 @@ fn gen_augment_clap_enum(
let ty = &unnamed[0];
quote_spanned! { ty.span()=>
{
let #app_var = <#ty as ::structopt::StructOpt>::augment_clap(#app_var);
if <#ty as ::structopt::StructOpt>::is_subcommand() {
let #app_var = <#ty as ::structopt::StructOptInternal>::augment_clap(
#app_var
);
if <#ty as ::structopt::StructOptInternal>::is_subcommand() {
#app_var.setting(
::structopt::clap::AppSettings::SubcommandRequiredElseHelp
)
Expand Down Expand Up @@ -498,7 +502,7 @@ fn gen_augment_clap_enum(
fn gen_from_clap_enum(name: &Ident) -> TokenStream {
quote! {
fn from_clap(matches: &::structopt::clap::ArgMatches) -> Self {
<#name as ::structopt::StructOpt>::from_subcommand(matches.subcommand())
<#name as ::structopt::StructOptInternal>::from_subcommand(matches.subcommand())
.unwrap()
}
}
Expand Down Expand Up @@ -580,11 +584,18 @@ fn impl_structopt_for_struct(
quote! {
#[allow(unused_variables)]
#[allow(unknown_lints)]
#[allow(clippy)]
#[allow(clippy::all)]
#[allow(dead_code, unreachable_code)]
impl ::structopt::StructOpt for #name {
#clap_tokens
#from_clap
}

#[allow(unused_variables)]
#[allow(unknown_lints)]
#[allow(clippy::all)]
#[allow(dead_code, unreachable_code)]
impl ::structopt::StructOptInternal for #name {
#augment_clap
fn is_subcommand() -> bool { false }
}
Expand Down Expand Up @@ -613,6 +624,13 @@ fn impl_structopt_for_enum(
impl ::structopt::StructOpt for #name {
#clap_tokens
#from_clap
}

#[allow(unused_variables)]
#[allow(unknown_lints)]
#[allow(clippy::all)]
#[allow(dead_code, unreachable_code)]
impl ::structopt::StructOptInternal for #name {
#augment_clap
#from_subcommand
fn is_subcommand() -> bool { true }
Expand Down