Skip to content

Commit

Permalink
cli: move cmd_config_list() entry point next to Args struct
Browse files Browse the repository at this point in the history
  • Loading branch information
yuja committed Aug 1, 2024
1 parent 9168500 commit f57a7e5
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions cli/src/commands/config/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,6 @@ pub struct ConfigListArgs {
template: Option<String>,
}

// AnnotatedValue will be cloned internally in the templater. If the cloning
// cost matters, wrap it with Rc.
fn config_template_language() -> GenericTemplateLanguage<'static, AnnotatedValue> {
type L = GenericTemplateLanguage<'static, AnnotatedValue>;
let mut language = L::new();
// "name" instead of "path" to avoid confusion with the source file path
language.add_keyword("name", |self_property| {
let out_property = self_property.map(|annotated| annotated.path.to_string());
Ok(L::wrap_string(out_property))
});
language.add_keyword("value", |self_property| {
// TODO: would be nice if we can provide raw dynamically-typed value
let out_property =
self_property.and_then(|annotated| Ok(to_toml_value(&annotated.value)?.to_string()));
Ok(L::wrap_string(out_property))
});
language.add_keyword("overridden", |self_property| {
let out_property = self_property.map(|annotated| annotated.is_overridden);
Ok(L::wrap_boolean(out_property))
});
language
}

#[instrument(skip_all)]
pub fn cmd_config_list(
ui: &mut Ui,
Expand Down Expand Up @@ -129,3 +106,26 @@ pub fn cmd_config_list(
}
Ok(())
}

// AnnotatedValue will be cloned internally in the templater. If the cloning
// cost matters, wrap it with Rc.
fn config_template_language() -> GenericTemplateLanguage<'static, AnnotatedValue> {
type L = GenericTemplateLanguage<'static, AnnotatedValue>;
let mut language = L::new();
// "name" instead of "path" to avoid confusion with the source file path
language.add_keyword("name", |self_property| {
let out_property = self_property.map(|annotated| annotated.path.to_string());
Ok(L::wrap_string(out_property))
});
language.add_keyword("value", |self_property| {
// TODO: would be nice if we can provide raw dynamically-typed value
let out_property =
self_property.and_then(|annotated| Ok(to_toml_value(&annotated.value)?.to_string()));
Ok(L::wrap_string(out_property))
});
language.add_keyword("overridden", |self_property| {
let out_property = self_property.map(|annotated| annotated.is_overridden);
Ok(L::wrap_boolean(out_property))
});
language
}

0 comments on commit f57a7e5

Please sign in to comment.