Skip to content

Commit

Permalink
chore(test): Add back the default_templates method to make weaver_f…
Browse files Browse the repository at this point in the history
…orge unit tests happy again.
  • Loading branch information
lquerel committed Jun 4, 2024
1 parent db8d2c0 commit d512563
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 2 deletions.
109 changes: 108 additions & 1 deletion crates/weaver_forge/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub(crate) struct TargetConfig {

/// Parameters for the templates.
/// These parameters can be overridden by parameters passed to the CLI.
#[serde(default)]
#[serde(default = "default_templates")]
pub(crate) params: HashMap<String, Value>,

/// Configuration for the templates.
Expand All @@ -94,6 +94,113 @@ pub(crate) struct TargetConfig {
pub(crate) acronyms: Vec<String>,
}

fn default_templates() -> Vec<TemplateConfig> {
vec![
TemplateConfig {
pattern: Glob::new("**/registry.md").expect("Invalid pattern"),
filter: Filter::try_new(".").expect("Invalid filter"),
r#if: None,
application_mode: ApplicationMode::Single,
},
TemplateConfig {
pattern: Glob::new("**/attribute_group.md").expect("Invalid pattern"),
filter: Filter::try_new(".groups[] | select(.type == \"attribute_group\")")
.expect("Invalid filter"),
r#if: None,
application_mode: ApplicationMode::Each,
},
TemplateConfig {
pattern: Glob::new("**/attribute_groups.md").expect("Invalid pattern"),
filter: Filter::try_new(".groups[] | select(.type == \"attribute_group\")")
.expect("Invalid filter"),
r#if: None,
application_mode: ApplicationMode::Single,
},
TemplateConfig {
pattern: Glob::new("**/event.md").expect("Invalid pattern"),
filter: Filter::try_new(".groups[] | select(.type == \"event\")")
.expect("Invalid filter"),
r#if: None,
application_mode: ApplicationMode::Each,
},
TemplateConfig {
pattern: Glob::new("**/events.md").expect("Invalid pattern"),
filter: Filter::try_new(".groups[] | select(.type == \"event\")")
.expect("Invalid filter"),
r#if: None,
application_mode: ApplicationMode::Single,
},
TemplateConfig {
pattern: Glob::new("**/group.md").expect("Invalid pattern"),
filter: Filter::try_new(".groups").expect("Invalid filter"),
r#if: None,
application_mode: ApplicationMode::Each,
},
TemplateConfig {
pattern: Glob::new("**/groups.md").expect("Invalid pattern"),
filter: Filter::try_new(".groups").expect("Invalid filter"),
r#if: None,
application_mode: ApplicationMode::Single,
},
TemplateConfig {
pattern: Glob::new("**/metric.md").expect("Invalid pattern"),
filter: Filter::try_new(".groups[] | select(.type == \"metric\")")
.expect("Invalid filter"),
r#if: None,
application_mode: ApplicationMode::Each,
},
TemplateConfig {
pattern: Glob::new("**/metrics.md").expect("Invalid pattern"),
filter: Filter::try_new(".groups[] | select(.type == \"metric\")")
.expect("Invalid filter"),
r#if: None,
application_mode: ApplicationMode::Single,
},
TemplateConfig {
pattern: Glob::new("**/resource.md").expect("Invalid pattern"),
filter: Filter::try_new(".groups[] | select(.type == \"resource\")")
.expect("Invalid filter"),
r#if: None,
application_mode: ApplicationMode::Each,
},
TemplateConfig {
pattern: Glob::new("**/resources.md").expect("Invalid pattern"),
filter: Filter::try_new(".groups[] | select(.type == \"resource\")")
.expect("Invalid filter"),
r#if: None,
application_mode: ApplicationMode::Single,
},
TemplateConfig {
pattern: Glob::new("**/scope.md").expect("Invalid pattern"),
filter: Filter::try_new(".groups[] | select(.type == \"scope\")")
.expect("Invalid filter"),
r#if: None,
application_mode: ApplicationMode::Each,
},
TemplateConfig {
pattern: Glob::new("**/scopes.md").expect("Invalid pattern"),
filter: Filter::try_new(".groups[] | select(.type == \"scope\")")
.expect("Invalid filter"),
r#if: None,
application_mode: ApplicationMode::Single,
},
TemplateConfig {
pattern: Glob::new("**/span.md").expect("Invalid pattern"),
filter: Filter::try_new(".groups[] | select(.type == \"span\")")
.expect("Invalid filter"),
r#if: None,
application_mode: ApplicationMode::Each,
},
TemplateConfig {
pattern: Glob::new("**/spans.md").expect("Invalid pattern"),
filter: Filter::try_new(".groups[] | select(.type == \"span\")")
.expect("Invalid filter"),
r#if: None,
application_mode: ApplicationMode::Single,
},
]
}

/// Parameters defined in the command line via the `--params` argument.
#[derive(Deserialize, Debug, Clone, Default)]
pub struct Params {
Expand Down
2 changes: 1 addition & 1 deletion src/registry/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub struct RegistryGenerateArgs {

/// Parameters key=value, defined in the command line, to pass to the templates.
/// The value must be a valid YAML value.
#[arg(long, value_parser = parse_key_val)]
#[arg(short= 'D', long, value_parser = parse_key_val)]
pub param: Option<Vec<(String, Value)>>,

/// Parameters, defined in a YAML file, to pass to the templates.
Expand Down

0 comments on commit d512563

Please sign in to comment.