use clap::{App, Arg, SubCommand};
use orcs::{run_command, Error};
use std::process::exit;
use tracing::Level;
fn main() {
match cli() {
Ok(_) => (),
Err(err) => {
println!("Error: {}", err);
exit(1)
}
}
}
fn cli() -> Result<(), Error> {
let app = App::new("orcs")
.arg(Arg::with_name("debug").short("d").global(true))
.arg(
Arg::with_name("path")
.short("p")
.long("path")
.value_name("PATH")
.default_value(".")
.global(true),
)
.subcommand(
SubCommand::with_name("get")
.about("retrieve a parameter value")
.arg(Arg::with_name("name").required(true))
.arg(
Arg::with_name("output")
.short("o")
.value_name("OUTPUT_FILE")
.required(false),
),
)
.subcommand(
SubCommand::with_name("get-file")
.about("retrieve a parameter value")
.arg(Arg::with_name("name").required(true))
.arg(Arg::with_name("filename").required(true)),
)
.subcommand(
SubCommand::with_name("init")
.about("Initialize a new project")
.arg(Arg::with_name("name").required(false))
.arg(
Arg::with_name("template")
.short("t")
.long("template")
.value_name("TEMPLATE")
.required(false),
),
)
.subcommand(
SubCommand::with_name("load")
.about("Load a project or service file")
.arg(Arg::with_name("name").required(false)),
)
.subcommand(
SubCommand::with_name("new")
.about("Create a new service")
.arg(
Arg::with_name("type")
.required(true)
.possible_values(&["service", "recipe"]),
)
.arg(Arg::with_name("name").required(true))
.arg(
Arg::with_name("template")
.short("t")
.long("template")
.value_name("TEMPLATE")
.required(false),
),
)
.subcommand(
SubCommand::with_name("run")
.about("Run the provided stage")
.arg(Arg::with_name("stage").required(true))
.arg(Arg::with_name("service").required(false)),
)
.subcommand(
SubCommand::with_name("set")
.about("retrieve a parameter value")
.arg(Arg::with_name("name").required(true))
.arg(Arg::with_name("value").required(true)),
)
.subcommand(
SubCommand::with_name("set-file")
.about("retrieve a parameter value")
.arg(Arg::with_name("name").required(true))
.arg(Arg::with_name("filename").required(true)),
);
let matches = app.get_matches();
let log_level = if matches.is_present("debug") {
Level::TRACE
} else {
Level::INFO
};
let project_path = matches.value_of("path").unwrap_or(".");
let subscriber = tracing_subscriber::fmt().with_max_level(log_level).finish();
tracing::subscriber::set_global_default(subscriber).expect("no global subscriber has been set");
if let (cmd, Some(sub)) = matches.subcommand() {
run_command(project_path, cmd, sub)?;
};
Ok(())
}