Skip to content

Commit

Permalink
Fix a privacy bug
Browse files Browse the repository at this point in the history
Fix #24
  • Loading branch information
TeXitoi committed Nov 1, 2017
1 parent f7a4be1 commit 63d6037
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
6 changes: 4 additions & 2 deletions structopt-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ fn gen_augment_clap(fields: &[Field]) -> quote::Tokens {
let app_var = Ident::new("app");
let augmentation = gen_augmentation(fields, &app_var);
quote! {
fn augment_clap<'a, 'b>(#app_var: _structopt::clap::App<'a, 'b>) -> _structopt::clap::App<'a, 'b> {
pub fn augment_clap<'a, 'b>(#app_var: _structopt::clap::App<'a, 'b>) -> _structopt::clap::App<'a, 'b> {
#augmentation
}
}
Expand Down Expand Up @@ -594,6 +594,7 @@ fn gen_augment_clap_enum(variants: &[Variant]) -> quote::Tokens {

fn gen_from_clap_enum(name: &Ident) -> quote::Tokens {
quote! {
#[doc(hidden)]
fn from_clap(matches: _structopt::clap::ArgMatches) -> Self {
#name ::from_subcommand(matches.subcommand())
.unwrap()
Expand Down Expand Up @@ -625,7 +626,8 @@ fn gen_from_subcommand(name: &Ident, variants: &[Variant]) -> quote::Tokens {
});

quote! {
fn from_subcommand<'a, 'b>(sub: (&'b str, Option<&'b _structopt::clap::ArgMatches<'a>>)) -> Option<Self> {
#[doc(hidden)]
pub fn from_subcommand<'a, 'b>(sub: (&'b str, Option<&'b _structopt::clap::ArgMatches<'a>>)) -> Option<Self> {
match sub {
#( #match_arms ),*,
_ => None
Expand Down
29 changes: 29 additions & 0 deletions tests/privacy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2017 Guillaume Pinot <texitoi(a)texitoi.eu>
//
// This work is free. You can redistribute it and/or modify it under
// the terms of the Do What The Fuck You Want To Public License,
// Version 2, as published by Sam Hocevar. See the COPYING file for
// more details.

extern crate structopt;
#[macro_use]
extern crate structopt_derive;

mod options {
#[derive(Debug, StructOpt)]
pub struct Options {
#[structopt(subcommand)]
pub subcommand: ::subcommands::SubCommand,
}
}

mod subcommands {
#[derive(Debug, StructOpt)]
pub enum SubCommand {
#[structopt(name = "foo", about = "foo")]
Foo {
#[structopt(help = "foo")]
bars: Vec<String>,
},
}
}

0 comments on commit 63d6037

Please sign in to comment.