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

remove clap feature from LogLevel #8465

Closed
mattsse opened this issue May 29, 2024 · 1 comment · Fixed by #8573
Closed

remove clap feature from LogLevel #8465

mattsse opened this issue May 29, 2024 · 1 comment · Fixed by #8573
Assignees
Labels
C-debt Refactor of code section that is hard to understand or maintain C-enhancement New feature or request D-good-first-issue Nice and easy! A great choice to get started

Comments

@mattsse
Copy link
Collaborator

mattsse commented May 29, 2024

Describe the feature

enabling features for crates deep in the stack is very inconvenient

#[cfg_attr(feature = "clap", derive(clap::ValueEnum))]

This feature is only used here

/// Database logging level. Levels higher than "notice" require a debug build.
#[arg(long = "db.log-level", value_enum)]
pub log_level: Option<LogLevel>,

TODO

  • remove clap support and instead implement a value parser that manually does this

this is the generated code

impl clap::ValueEnum for LogLevel {
        fn value_variants<'a>() -> &'a [Self] {
            &[
                Self::Fatal,
                Self::Error,
                Self::Warn,
                Self::Notice,
                Self::Verbose,
                Self::Debug,
                Self::Trace,
                Self::Extra,
            ]
        }
        fn to_possible_value<'a>(
            &self,
        ) -> ::std::option::Option<clap::builder::PossibleValue> {
            match self {
                Self::Fatal => {
                    Some({
                        clap::builder::PossibleValue::new("fatal")
                            .help(
                                "Enables logging for critical conditions, i.e. assertion failures",
                            )
                    })
                }
                Self::Error => {
                    Some({
                        clap::builder::PossibleValue::new("error")
                            .help("Enables logging for error conditions")
                    })
                }
                Self::Warn => {
                    Some({
                        clap::builder::PossibleValue::new("warn")
                            .help("Enables logging for warning conditions")
                    })
                }
                Self::Notice => {
                    Some({
                        clap::builder::PossibleValue::new("notice")
                            .help("Enables logging for normal but significant condition")
                    })
                }
                Self::Verbose => {
                    Some({
                        clap::builder::PossibleValue::new("verbose")
                            .help("Enables logging for verbose informational")
                    })
                }
                Self::Debug => {
                    Some({
                        clap::builder::PossibleValue::new("debug")
                            .help("Enables logging for debug-level messages")
                    })
                }
                Self::Trace => {
                    Some({
                        clap::builder::PossibleValue::new("trace")
                            .help("Enables logging for trace debug-level messages")
                    })
                }
                Self::Extra => {
                    Some({
                        clap::builder::PossibleValue::new("extra")
                            .help("Enables logging for extra debug-level messages")
                    })
                }
                _ => None,
            }
        }
    }

this can also be solved by copying the value_variants and add a fn help_message which the value parser then uses

Additional context

No response

@mattsse mattsse added C-enhancement New feature or request S-needs-triage This issue needs to be labelled D-good-first-issue Nice and easy! A great choice to get started C-debt Refactor of code section that is hard to understand or maintain and removed S-needs-triage This issue needs to be labelled labels May 29, 2024
@JackG-eth
Copy link
Contributor

Happy to take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-debt Refactor of code section that is hard to understand or maintain C-enhancement New feature or request D-good-first-issue Nice and easy! A great choice to get started
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants