Skip to content

refactor(styles): make styles example use a const#5636

Merged
epage merged 1 commit intoclap-rs:masterfrom
gibfahn:styles_const
Aug 8, 2024
Merged

refactor(styles): make styles example use a const#5636
epage merged 1 commit intoclap-rs:masterfrom
gibfahn:styles_const

Conversation

@gibfahn
Copy link
Copy Markdown
Contributor

@gibfahn gibfahn commented Aug 8, 2024

I was trying to set up colours for the derive macro, and copying this didn't immediately work, but using .bold() as per #3234 (comment) did work, so figured it would be worth updating the defaults so things are a bit easier for the next person.


Commits (oldest to newest)

6f215ee refactor(styles): make styles example use a const

This makes it easier to copy this example for use in the derive API,
like so:

const STYLES: Styles = Styles::styled()
    .header(AnsiColor::Green.on_default().bold())
    .usage(AnsiColor::Green.on_default().bold())
    .literal(AnsiColor::Blue.on_default().bold())
    .placeholder(AnsiColor::Cyan.on_default());

#[derive(Parser)]
#[clap(styles = STYLES)]
struct Cmd {
  ...
}

If you use the | method then it's not a constant function.


@epage
Copy link
Copy Markdown
Member

epage commented Aug 8, 2024

Looks like this needs to bump the version of anstyle to pass CI

This makes it easier to copy this example for use in the derive API,
like so:

```rust
const STYLES: Styles = Styles::styled()
    .header(AnsiColor::Green.on_default().bold())
    .usage(AnsiColor::Green.on_default().bold())
    .literal(AnsiColor::Blue.on_default().bold())
    .placeholder(AnsiColor::Cyan.on_default());

#[derive(Parser)]
#[clap(styles = STYLES)]
struct Cmd {
  ...
}
```

If you use the `|` method then it's not a constant function.
@epage epage merged commit 6fb49d0 into clap-rs:master Aug 8, 2024
@epage
Copy link
Copy Markdown
Member

epage commented Aug 8, 2024

Thanks!

@gibfahn gibfahn deleted the styles_const branch August 8, 2024 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants