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(component_ref) = args.component_ref {
45 passthrough_args.push("--component-ref".into());
46 passthrough_args.push(component_ref.into());
47 }
48 if let Some(local_wasm) = args.local_wasm {
49 passthrough_args.push("--local-wasm".into());
50 passthrough_args.push(local_wasm.into_os_string());
51 }
52 if args.pin {
53 passthrough_args.push("--pin".into());
54 }
55 if let Some(alias) = args.pack_alias {
56 passthrough_args.push("--pack-alias".into());
57 passthrough_args.push(alias.into());
58 }
59 if let Some(op) = args.operation {
60 passthrough_args.push("--operation".into());
61 passthrough_args.push(op.into());
62 }
63 passthrough_args.push("--payload".into());
64 passthrough_args.push(args.payload.into());
65 if args.routing_out {
66 passthrough_args.push("--routing-out".into());
67 }
68 if args.routing_reply {
69 passthrough_args.push("--routing-reply".into());
70 }
71 if let Some(next) = args.routing_next {
72 passthrough_args.push("--routing-next".into());
73 passthrough_args.push(next.into());
74 }
75 if let Some(multi) = args.routing_multi_to {
76 passthrough_args.push("--routing-multi-to".into());
77 passthrough_args.push(multi.into());
78 }
79 if let Some(json) = args.routing_json {
80 passthrough_args.push("--routing-json".into());
81 passthrough_args.push(json.into_os_string());
82 }
83 if args.routing_to_anchor {
84 passthrough_args.push("--routing-to-anchor".into());
85 }
86 }
87 FlowAddStepMode::Config => {
88 passthrough_args.push("--mode".into());
89 passthrough_args.push("config".into());
90 if let Some(config) = args.config_flow {
91 passthrough_args.push("--config-flow".into());
92 passthrough_args.push(config.into_os_string());
93 }
94 if let Some(answers) = args.answers {
95 passthrough_args.push("--answers".into());
96 passthrough_args.push(answers.into());
97 }
98 if let Some(file) = args.answers_file {
99 passthrough_args.push("--answers-file".into());
100 passthrough_args.push(file.into_os_string());
101 }
102 }
103 }
104
105 if args.allow_cycles {
106 passthrough_args.push("--allow-cycles".into());
107 }
108 if args.write {
109 passthrough_args.push("--write".into());
110 }
111 if args.validate_only {
112 passthrough_args.push("--validate-only".into());
113 }
114 if let Some(node_id) = args.node_id {
115 passthrough_args.push("--node-id".into());
116 passthrough_args.push(node_id.into());
117 }
118 for manifest in args.manifests {
119 passthrough_args.push("--manifest".into());
120 passthrough_args.push(manifest.into_os_string());
121 }
122
123 let status = run_passthrough(&bin, &passthrough_args, args.verbose)?;
124 process::exit(status.code().unwrap_or(1));
125}