Skip to content

Commit

Permalink
refactor(styles): make styles example use a const
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gibfahn committed Aug 8, 2024
1 parent ecb4dca commit 6f215ee
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion clap_builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ clap_lex = { path = "../clap_lex", version = "0.7.0" }
unicase = { version = "2.6.0", optional = true }
strsim = { version = "0.11.0", optional = true }
anstream = { version = "0.6.7", optional = true }
anstyle = "1.0.0"
anstyle = "1.0.8"
terminal_size = { version = "0.3.0", optional = true }
backtrace = { version = "0.3.73", optional = true }
unicode-width = { version = "0.1.9", optional = true }
Expand Down
10 changes: 5 additions & 5 deletions clap_builder/src/builder/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1199,13 +1199,13 @@ impl Command {
/// ```no_run
/// # use clap_builder as clap;
/// # use clap::{Command, ColorChoice, builder::styling};
/// let styles = styling::Styles::styled()
/// .header(styling::AnsiColor::Green.on_default() | styling::Effects::BOLD)
/// .usage(styling::AnsiColor::Green.on_default() | styling::Effects::BOLD)
/// .literal(styling::AnsiColor::Blue.on_default() | styling::Effects::BOLD)
/// const STYLES: styling::Styles = styling::Styles::styled()
/// .header(styling::AnsiColor::Green.on_default().bold())
/// .usage(styling::AnsiColor::Green.on_default().bold())
/// .literal(styling::AnsiColor::Blue.on_default().bold())
/// .placeholder(styling::AnsiColor::Cyan.on_default());
/// Command::new("myprog")
/// .styles(styles)
/// .styles(STYLES)
/// .get_matches();
/// ```
#[cfg(feature = "color")]
Expand Down
10 changes: 5 additions & 5 deletions src/bin/stdio-fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ fn main() {
#[cfg(feature = "color")]
{
use clap::builder::styling;
let styles = styling::Styles::styled()
.header(styling::AnsiColor::Green.on_default() | styling::Effects::BOLD)
.usage(styling::AnsiColor::Green.on_default() | styling::Effects::BOLD)
.literal(styling::AnsiColor::Blue.on_default() | styling::Effects::BOLD)
const STYLES: styling::Styles = styling::Styles::styled()
.header(styling::AnsiColor::Green.on_default().bold())
.usage(styling::AnsiColor::Green.on_default().bold())
.literal(styling::AnsiColor::Blue.on_default().bold())
.placeholder(styling::AnsiColor::Cyan.on_default());
cmd = cmd.styles(styles);
cmd = cmd.styles(STYLES);
}
cmd.get_matches();
}

0 comments on commit 6f215ee

Please sign in to comment.