pub fn run(args: Vec<String>) -> i32 {
match DataCli::try_parse_from(args) {
Ok(cli) => dispatch(cli.command),
Err(err) => {
let _ = err.print();
match err.kind() {
clap::error::ErrorKind::DisplayHelp | clap::error::ErrorKind::DisplayVersion => 0,
_ => 2,
}
}
}
}
pub(crate) fn dispatch(command: DataCommand) -> i32 {
match command {
DataCommand::Routines(cmd) => dispatch_routine(*cmd),
DataCommand::Schedule(ScheduleCmd::Trigger { id }) => request(
"POST",
&format!("{}/scheduled-trigger", routine_path(&id)),
None,
),
DataCommand::Enable { routine, json } => set_routine_enabled(&routine, true, json),
DataCommand::Disable { routine, json } => set_routine_enabled(&routine, false, json),
DataCommand::Agents => request("GET", "/api/v1/agents", None),
}
}