Skip to main content

ironflow_cli/commands/
mod.rs

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