greentic_dev/
flow_cmd.rs

1use std::ffi::OsString;
2use std::process;
3
4use crate::cli::{FlowAddStepArgs, FlowAddStepMode, FlowDoctorArgs};
5use crate::passthrough::{resolve_binary, run_passthrough};
6use crate::path_safety::normalize_under_root;
7use anyhow::{Context, Result};
8
9pub fn validate(args: FlowDoctorArgs) -> Result<()> {
10    eprintln!("greentic-dev flow validate is deprecated; forwarding to greentic-flow doctor");
11    doctor(args)
12}
13
14pub fn doctor(args: FlowDoctorArgs) -> Result<()> {
15    let bin = resolve_binary("greentic-flow")?;
16    let mut passthrough_args: Vec<OsString> = vec!["doctor".into()];
17    passthrough_args.extend(args.passthrough.into_iter().map(OsString::from));
18    let status = run_passthrough(&bin, &passthrough_args, false)?;
19    process::exit(status.code().unwrap_or(1));
20}
21
22pub fn run_add_step(args: FlowAddStepArgs) -> Result<()> {
23    let root = std::env::current_dir()
24        .context("failed to resolve workspace root")?
25        .canonicalize()
26        .context("failed to canonicalize workspace root")?;
27    let flow = normalize_under_root(&root, &args.flow_path)?;
28
29    let bin = resolve_binary("greentic-flow")?;
30    let mut passthrough_args: Vec<OsString> =
31        vec!["add-step".into(), "--flow".into(), flow.into_os_string()];
32
33    if let Some(after) = args.after {
34        passthrough_args.push("--after".into());
35        passthrough_args.push(after.into());
36    }
37
38    match args.mode {
39        FlowAddStepMode::Default => {
40            if let Some(component) = args.component_id {
41                passthrough_args.push("--component".into());
42                passthrough_args.push(component.into());
43            }
44            if let Some(alias) = args.pack_alias {
45                passthrough_args.push("--pack-alias".into());
46                passthrough_args.push(alias.into());
47            }
48            if let Some(op) = args.operation {
49                passthrough_args.push("--operation".into());
50                passthrough_args.push(op.into());
51            }
52            passthrough_args.push("--payload".into());
53            passthrough_args.push(args.payload.into());
54            if let Some(routing) = args.routing {
55                passthrough_args.push("--routing".into());
56                passthrough_args.push(routing.into());
57            }
58        }
59        FlowAddStepMode::Config => {
60            passthrough_args.push("--mode".into());
61            passthrough_args.push("config".into());
62            if let Some(config) = args.config_flow {
63                passthrough_args.push("--config-flow".into());
64                passthrough_args.push(config.into_os_string());
65            }
66            if let Some(answers) = args.answers {
67                passthrough_args.push("--answers".into());
68                passthrough_args.push(answers.into());
69            }
70            if let Some(file) = args.answers_file {
71                passthrough_args.push("--answers-file".into());
72                passthrough_args.push(file.into_os_string());
73            }
74        }
75    }
76
77    if args.allow_cycles {
78        passthrough_args.push("--allow-cycles".into());
79    }
80    if args.write {
81        passthrough_args.push("--write".into());
82    }
83    if args.validate_only {
84        passthrough_args.push("--validate-only".into());
85    }
86    if let Some(node_id) = args.node_id {
87        passthrough_args.push("--node-id".into());
88        passthrough_args.push(node_id.into());
89    }
90    for manifest in args.manifests {
91        passthrough_args.push("--manifest".into());
92        passthrough_args.push(manifest.into_os_string());
93    }
94
95    let status = run_passthrough(&bin, &passthrough_args, args.verbose)?;
96    process::exit(status.code().unwrap_or(1));
97}