use cli_forge::{App, Arg, Command, out, style};
fn main() {
let mut app = App::new("demo")
.version(env!("CARGO_PKG_VERSION"))
.help_header("demo — a cli-forge example")
.help_footer("see https://github.com/jamesgober/cli-forge");
app.register(
Command::new("build")
.about("compile the project")
.arg(Arg::flag("release").short('r').help("optimized build"))
.arg(
Arg::option("jobs")
.short('j')
.default("1")
.help("parallel jobs"),
)
.run(|m| {
let profile = if m.flag("release") {
"release"
} else {
"debug"
};
let jobs = m.value("jobs").unwrap_or("1");
out(style(format!("building [{profile}] with {jobs} job(s)"))
.cyan()
.bold());
}),
);
app.register(
Command::new("greet")
.about("print a greeting")
.arg(Arg::positional("name").default("world"))
.run(|m| {
let name = m.value("name").unwrap_or("world");
out(format!("hello, {name}"));
}),
);
app.register(
Command::new("remote")
.about("manage remotes")
.subcommand(
Command::new("add")
.about("add a remote")
.arg(Arg::positional("name").required(true))
.run(|m| out(format!("added remote {}", m.value("name").unwrap_or("?")))),
)
.subcommand(
Command::new("remove")
.aliases(["rm", "del"])
.about("remove a remote")
.arg(Arg::positional("name").required(true))
.run(|m| out(format!("removed remote {}", m.value("name").unwrap_or("?")))),
),
);
let _matches = app.parse();
}