1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use std::collections::HashMap;
use std::path::Path;

use wick_asset_reference::AssetReference;
use wick_packet::RuntimeConfig;

use crate::config::template_config::Renderable;
use crate::config::{Binding, ComponentOperationExpression, ImportDefinition};
use crate::error::ManifestError;
use crate::ExpandImports;

#[derive(
  Debug,
  Clone,
  PartialEq,
  derive_asset_container::AssetManager,
  property::Property,
  serde::Serialize,
  derive_builder::Builder,
)]
#[builder(setter(into))]
#[asset(asset(AssetReference))]
#[property(get(public), set(private), mut(public, suffix = "_mut"))]

/// Normalized representation of a CLI trigger configuration.
pub struct CliConfig {
  pub(crate) operation: ComponentOperationExpression,
}

impl ExpandImports for CliConfig {
  type Error = ManifestError;
  fn expand_imports(
    &mut self,
    bindings: &mut Vec<Binding<ImportDefinition>>,
    trigger_index: usize,
  ) -> Result<(), Self::Error> {
    let id = format!("trigger_{}", trigger_index);
    self.operation_mut().maybe_import(&id, bindings);
    Ok(())
  }
}

impl Renderable for CliConfig {
  fn render_config(
    &mut self,
    source: Option<&Path>,
    root_config: Option<&RuntimeConfig>,
    env: Option<&HashMap<String, String>>,
  ) -> Result<(), ManifestError> {
    self.operation.render_config(source, root_config, env)
  }
}