Skip to main content

ironflow_cli/commands/
mod.rs

1//! CLI command handlers.
2
3use std::str::FromStr;
4
5pub mod api_key;
6pub mod audit_log;
7pub mod dashboard;
8pub mod delegation;
9pub mod init;
10pub mod logs;
11pub mod run;
12pub mod schedule;
13pub mod secret;
14pub mod stats;
15pub mod template;
16pub mod user;
17pub mod workflow;
18
19/// Parse a CLI value into one of the SDK's generated enums.
20///
21/// The generated `FromStr` error carries no information, so it is replaced by a
22/// message that tells the caller what to type instead. The generated enums
23/// expose no variant iterator, hence `accepted` being passed in.
24///
25/// # Errors
26///
27/// Returns the list of accepted values when `raw` is not one of them.
28pub(crate) fn parse_enum<T: FromStr + ToString>(
29    raw: &str,
30    accepted: &[T],
31    noun: &str,
32) -> Result<T, String> {
33    T::from_str(raw).map_err(|_| {
34        let accepted: Vec<String> = accepted.iter().map(ToString::to_string).collect();
35        format!("unknown {noun} '{raw}'; accepted: {}", accepted.join(", "))
36    })
37}