use clap::{arg, Command};
use std::error::Error;
use log::LevelFilter;
use whiley::command::{build,clean,init,install,run};
use whiley::{init_logging,init_whileyhome};
fn main() -> Result<(),Box<dyn Error>> {
let matches = Command::new("wy")
.about("Whiley Build Tool")
.version("0.6.0")
.subcommand_required(true)
.arg(arg!(--verbose "Show verbose output"))
.subcommand(
Command::new("build").about("Build local package(s)"))
.subcommand(
Command::new("clean").about("Remove all generated (binary) files"))
.subcommand(
Command::new("init").about("Create a new Whiley package in an existing directory"))
.subcommand(
Command::new("install").about("Install package in local repository"))
.subcommand(
Command::new("run").about("Run package (via interpreter)"))
.get_matches();
let verbose = matches.is_present("verbose");
if verbose {
init_logging(LevelFilter::Info);
}
let whileyhome = init_whileyhome();
let ok = match matches.subcommand() {
Some(("build", _)) => build(&whileyhome),
Some(("clean", _)) => clean(&whileyhome),
Some(("init", _)) => init(&whileyhome),
Some(("install", _)) => install(&whileyhome),
Some(("run", _)) => run(&whileyhome),
_ => unreachable!()
}?;
let exitcode = if ok { 0 } else { 1 };
std::process::exit(exitcode);
}