use crate::models::{Pipeline, Task};
use clap::{crate_version, Arg, ArgAction, Command};
pub fn cli_builder() -> Command {
Command::new("rox")
.about("Rox: The Robust Developer Experience CLI")
.version(crate_version!())
.arg_required_else_help(true)
.allow_external_subcommands(true)
.arg(
Arg::new("roxfile")
.long("file")
.short('f')
.default_value("roxfile.yml")
.help("Path to a Roxfile"),
)
.arg(
Arg::new("skip-checks")
.long("skip-checks")
.short('s')
.required(false)
.action(ArgAction::SetTrue)
.help("Skip the version and file requirement checks."),
)
}
pub fn build_task_subcommands(tasks: &[Task]) -> Command {
let subcommands: Vec<Command> = tasks
.iter()
.filter(|target| !target.hide.unwrap_or_default())
.map(|task| Command::new(&task.name).about(task.description.clone().unwrap_or_default()))
.collect();
Command::new("task")
.about("Discrete executable tasks.")
.long_about("Discrete units of execution containing a single runnable command.")
.arg_required_else_help(true)
.subcommands(subcommands)
}
pub fn build_pipeline_subcommands(pipelines: &[Pipeline]) -> Command {
let subcommands: Vec<Command> = pipelines
.iter()
.map(|pipeline| {
Command::new(&pipeline.name).about(pipeline.description.clone().unwrap_or_default())
})
.collect();
Command::new("pl")
.about("Pipelines composed of multiple tasks.")
.arg_required_else_help(true)
.arg(
Arg::new("parallel")
.long("parallel")
.short('p')
.required(false)
.action(ArgAction::SetTrue)
.help("Run the pipeline's tasks in parallel."),
)
.subcommands(subcommands)
}