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

Colored help by default ? #39

Closed
bestouff opened this issue Dec 5, 2017 · 8 comments
Closed

Colored help by default ? #39

bestouff opened this issue Dec 5, 2017 · 8 comments
Labels

Comments

@bestouff
Copy link
Contributor

bestouff commented Dec 5, 2017

Hi,

Would it be possible to have AppSettings::ColoredHelp by default, or at least an easy way to enable it without calling into the underlying clap ?

@TeXitoi
Copy link
Owner

TeXitoi commented Dec 5, 2017

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

use structopt::StructOpt;

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

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

Does it fix your problem?

@bestouff
Copy link
Contributor Author

bestouff commented Dec 5, 2017

Indeed it does, thanks !
I'm sorry but I didn't understood this from the documentation. Maybe an example would help, do you want me to make a patch ?

@bestouff
Copy link
Contributor Author

bestouff commented Dec 5, 2017

Update: when trying that:

  #[derive(StructOpt, Debug)]                                                     
  #[structopt(name = "flashinit", about = "Boot disk populator.",                 
              setting_raw = "clap::AppSettings::ColoredHelp")]                    
  struct Opt {                                                                    
      #[structopt(help = "Disk device or disk image")]                            
      input: String,                                                              
  }                                                                               

I've got this:

   Compiling flashinit v0.1.0 (file:///home/xav/flashinit)
error[E0433]: failed to resolve. Use of undeclared type or module `clap`
  --> src/main.rs:16:10
   |
16 | #[derive(StructOpt, Debug)]
   |          ^^^^^^^^^ Use of undeclared type or module `clap`

error: aborting due to previous error

error: Could not compile `flashinit`.

To learn more, run the command again with --verbose.

@TeXitoi
Copy link
Owner

TeXitoi commented Dec 5, 2017

You have to extern crate clap; to expose clap.

I'm open to any improvement of the doc, feel free to submit a PR if you are inspired.

I tag this issue to doc, and close it when the doc is improved on this point.

@TeXitoi TeXitoi added the doc label Dec 5, 2017
@bestouff
Copy link
Contributor Author

bestouff commented Dec 5, 2017

Oh, so I have to also add clap as a dependency in Cargo.toml and track its version to match the one from structopt to avoid incompatibilities ... that's not an "easy" way anymore.

@TeXitoi
Copy link
Owner

TeXitoi commented Dec 5, 2017

StructOpt will always use clap version 2. It should be included in clap in the near future.

@bestouff
Copy link
Contributor Author

bestouff commented Dec 5, 2017

OK, I've added a note in the doc, see #40

@TeXitoi
Copy link
Owner

TeXitoi commented Dec 5, 2017

fixed by #40

@TeXitoi TeXitoi closed this as completed Dec 5, 2017
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
Projects
None yet
Development

No branches or pull requests

2 participants