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

It must be possible to not call author and about clap method #31

Closed
Boscop opened this issue Nov 22, 2017 · 13 comments
Closed

It must be possible to not call author and about clap method #31

Boscop opened this issue Nov 22, 2017 · 13 comments
Labels
enhancement We would love to have this feature! Feel free to supply a PR

Comments

@Boscop
Copy link

Boscop commented Nov 22, 2017

StructOpt will always call to author and about method. There should be a way to avoid these call. The goal is that if the value is the empty string, no call will be performed.

The issue originally was:

Order of args in --help should be in the order that fields appear in the options struct.
E.g. I want to have -i shown before -o in --help, but even though I put it before it in the struct, it appears after it in --help, why?

@TeXitoi
Copy link
Owner

TeXitoi commented Nov 23, 2017

StructOpt doesn't do anything about that, clap does.

You want that: https://docs.rs/clap/2.27.1/clap/enum.AppSettings.html#variant.DeriveDisplayOrder

Using structopt:

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

use structopt::StructOpt;

#[derive(StructOpt, Debug)]
#[structopt(setting_raw = "clap::AppSettings::DeriveDisplayOrder")]
struct Opt {
    #[structopt(short = "s")]
    speed: bool,
    #[structopt(short = "d")]
    debug: bool,
}

fn main() {
    let opt = Opt::from_args();
    println!("{:?}", opt);
}

It gives:

$ cargo run -- -h
    Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
     Running `target/debug/test -h`
test 0.0.1
Guillaume Pinot <texitoi@texitoi.eu>


USAGE:
    test [FLAGS]

FLAGS:
    -s               
    -d               
    -h, --help       Prints help information
    -V, --version    Prints version information

Does it answer your question?

@Boscop
Copy link
Author

Boscop commented Nov 23, 2017

Thanks!

Is there also a way to display the ARGS before OPTIONS and FLAGS?
Both in the USAGE line but also in the detailed list below.

@TeXitoi
Copy link
Owner

TeXitoi commented Nov 24, 2017

I can't find any similar feature in clap.

@TeXitoi
Copy link
Owner

TeXitoi commented Nov 24, 2017

By convention, ARGS will always be at the end on the USAGE line, because you can use -- to say "finish with options/flags, only args now" to be able to have args begining with a - (as used in my invocation of cargo run just above).

Thus, I think clap will not allow such a thing.

@Boscop
Copy link
Author

Boscop commented Nov 24, 2017

Ah ok, and how can I not include the about or author info in structopt?

@mattiasb
Copy link

Sorry for chiming in, but just to be sure: @Boscop did you check the Clap documentation for how to do it there? If yes and it is indeed possible to perform it with Clap, what troubles did you have translating that into StructOpt?

@Boscop
Copy link
Author

Boscop commented Nov 25, 2017

In clap it's done with .author(..) and .about(..), but Structopt generates the code calling .author(..) and .about(..). How can I tell it to not generate these calls?

@Boscop
Copy link
Author

Boscop commented Nov 25, 2017

If I pass author="" it calls .author("") (and it generates .about("") if my Cargo.toml description is not set). So those are two additional empty lines between the line containing <program name> <version> and USAGE (in the output of --help). So 3 empty lines in total (if both author and about are set there is 1 line as space).

How can I tell Structopt to not do these calls if the strings are empty? (So there will always be only 1 line space between the line containing <program name> <version> and USAGE).

@TeXitoi
Copy link
Owner

TeXitoi commented Nov 25, 2017

You're right, that's not possible for the moment. I'll manage the case empty string to not call the clap method on author and about.

@TeXitoi TeXitoi changed the title Order of args in --help should be struct field order It must be possible to not call author and about clap method Nov 25, 2017
@TeXitoi TeXitoi added the enhancement We would love to have this feature! Feel free to supply a PR label Nov 25, 2017
@TeXitoi
Copy link
Owner

TeXitoi commented Nov 25, 2017

v0.1.6 published

@Boscop
Copy link
Author

Boscop commented Nov 26, 2017

Thanks!

@Boscop
Copy link
Author

Boscop commented Apr 22, 2018

I just switched from 0.1 to 0.2 and this doesn't work anymore:
#[structopt(setting_raw = "clap::AppSettings::DeriveDisplayOrder)]"

What's the right way to do this now?

@TeXitoi
Copy link
Owner

TeXitoi commented Apr 23, 2018

The changelog explain everything.

Here, that's raw(setting ="..."))

Eijebong pushed a commit to Eijebong/structopt that referenced this issue Jan 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement We would love to have this feature! Feel free to supply a PR
Projects
None yet
Development

No branches or pull requests

3 participants