Skip to content
This repository has been archived by the owner on Jan 1, 2022. It is now read-only.

Allow templates to change the error message strings #168

Open
2 tasks done
epage opened this issue Dec 6, 2021 · 2 comments
Open
2 tasks done

Allow templates to change the error message strings #168

epage opened this issue Dec 6, 2021 · 2 comments

Comments

@epage
Copy link
Owner

epage commented Dec 6, 2021

Issue by filipelbc
Saturday Oct 31, 2020 at 21:07 GMT
Originally opened as clap-rs/clap#2196


Before anything, this library is great! Thanks!

Make sure you completed the following tasks

Describe your use case

I prefer printing ERROR: ... instead of error: ..., and to make the background red, instead of the foreground.

Describe the solution you'd like

Allow the user to set the "error: " string, which is currently hard-coded, see https://github.com/clap-rs/clap/blob/97b4fb639f846c5b910c318dd6c6f7d6da779d7d/src/parse/errors.rs#L401

Allow the user to change the colors, currently hard-coded, see https://github.com/clap-rs/clap/blob/97b4fb639f846c5b910c318dd6c6f7d6da779d7d/src/output/fmt.rs#L53

You could create a StyleSetting struct and a mechanism similar to AppSettings.

struct StyleSetting {
    string: &str,
    style: termcolor::ColorSpec,
}

enum StylePoint {
    ErrorStart,
    UsageStart,
    ...
}

let my_error_style = StyleSetting::new("ERROR: ", my_error_color_spec);

App::new("Foo")
    ...
    .style_setting(ErrorStart, my_error_style)
    ...

Additional context

Similar to clap-rs/clap#2035, but instead of allowing usage of Clap's error formatting, allow the user to customize Clap's messages and style to fit his preferences.

@epage epage added this to the 3.1 milestone Dec 6, 2021
@epage
Copy link
Owner Author

epage commented Dec 6, 2021

Comment by pksunkara
Saturday Oct 31, 2020 at 21:10 GMT


Note: Same as #1433 but this issue needs error message template support.

@epage
Copy link
Owner Author

epage commented Dec 6, 2021

Comment by pksunkara
Friday Nov 06, 2020 at 20:09 GMT


Might also be related to #1734

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant