use std::collections::HashMap;
#[macro_use]
extern crate clap;
use clap::{App, Arg, ArgMatches, SubCommand};
use std::process::exit;
const APP_VERSION: &str = "0.0.11";
fn main() {
let yaml = load_yaml!("panbuild.yml");
let panbuild_app: App = App::from_yaml(yaml).version(APP_VERSION);
let matches: ArgMatches = panbuild_app.get_matches();
if matches.is_present("version") {
println!("{}", APP_VERSION);
exit(0);
}
let command_name = matches.subcommand_name().unwrap_or("");
let mut flags: HashMap<String, bool> = HashMap::new();
let mut arguments: HashMap<String, String> = HashMap::new();
let command_name = match matches.subcommand_name() {
Some(command_name) => command_name,
None => {
eprintln!("Please provide a command to execute.");
eprintln!("{}", matches.usage());
exit(1);
}
};
let subcommand_matches = match matches.subcommand_matches(command_name) {
Some(subcommand_matches) => subcommand_matches,
None => {
eprintln!("Invalid arguments for command {}", command_name);
eprintln!("{}", matches.usage());
exit(1);
}
};
arguments
.entry("input_format".to_string())
.or_insert(subcommand_matches.value_of("input_format").unwrap_or("default").to_string());
arguments
.entry("input_file".to_string())
.or_insert(subcommand_matches.value_of("input_file").unwrap_or("default").to_string());
arguments
.entry("destination_format".to_string())
.or_insert(subcommand_matches.value_of("destination_format").unwrap_or("default").to_string());
arguments.entry("separator".to_string()).or_insert(subcommand_matches.value_of("separator").unwrap_or(",").to_string());
arguments
.entry("project_path".to_string())
.or_insert(subcommand_matches.value_of("project_path").unwrap_or(",").to_string());
arguments
.entry("package_name".to_string())
.or_insert(subcommand_matches.value_of("package_name").unwrap_or("").to_string());
arguments.entry("env_name".to_string()).or_insert(subcommand_matches.value_of("env_name").unwrap_or("").to_string());
let exit_code = panbuild::run(command_name, arguments);
exit(exit_code);
}