refactor: Replace Vec in options metadata with static array (#3433)

This commit is contained in:
Micha Reiser 2023-03-11 10:03:56 +01:00 committed by GitHub
parent 1e081cf9a6
commit cc8b13d3a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 204 additions and 81 deletions

View file

@ -1,35 +1,19 @@
use crate::ExitStatus;
use ruff::settings::{
options::Options,
options_base::{ConfigurationOptions, OptionEntry, OptionField},
};
use ruff::settings::options::Options;
#[allow(clippy::print_stdout)]
pub(crate) fn config(key: Option<&str>) -> ExitStatus {
let Some(entry) = Options::get(key) else {
println!("Unknown option");
return ExitStatus::Error;
};
match entry {
OptionEntry::Field(OptionField {
doc,
default,
value_type,
example,
}) => {
println!("{doc}");
println!();
println!("Default value: {default}");
println!("Type: {value_type}");
println!("Example usage:\n```toml\n{example}\n```");
}
OptionEntry::Group(entries) => {
for (name, _) in entries {
println!("{name}");
match key {
None => print!("{}", Options::metadata()),
Some(key) => match Options::metadata().get(key) {
None => {
println!("Unknown option");
return ExitStatus::Error;
}
}
Some(entry) => {
print!("{entry}");
}
},
}
ExitStatus::Success
}