liftoff 0.1.1

Get your coding project off the ground fast. See repo
Documentation
use clap::{App, Arg, SubCommand};
use liftoff::*;
use leg;
use std::{fs, path::Path};

fn main() {
    let matches = App::new("liftoff")
        .version("0.1.0")
        .author("Julian Gaal")
        .about("liftoff - get your coding project off the ground")
        .subcommand(SubCommand::with_name("new")
            .about("Create new project")
            .arg(
                Arg::with_name("name")
                    .value_name("NAME")
                    .required(true)
                    .takes_value(true),
            )
            .arg(
                Arg::with_name("config")
                    .short("c")
                    .long("config")
                    .required(true)
                    .value_name("FILE")
                    .help("The config file from file path or template, e.g. \"cpp\" (template), \"path/python.sane\" (file path)")
                    .takes_value(true),
            )
            .arg(
                Arg::with_name("nogit")
                    .long("nogit")
                    .multiple(false)
                    .help( "Git will not be initialized in project")
            )
            .arg(
                Arg::with_name("ci")
                    .long("ci")
                    .value_name("CI_SERVICE")
                    .help( "CI Service to be used")
                    .takes_value(true),
            )
            .arg(
                Arg::with_name("base_command")
                    .short("bc")
                    .long("base_cmd")
                    .value_name("CMD")
                    .help( "Command to be run before project is created")
                    .takes_value(true),
            )
            .arg(
                Arg::with_name("root")
                    .short("r")
                    .long("root")
                    .value_name("PATH")
                    .help( "Root directory in which project <NAME> will be created. Default: $PWD")
                    .takes_value(true),
            )
            .arg(
                Arg::with_name("author")
                    .short("a")
                    .long("author")
                    .value_name("NAME")
                    .help( "Author. Needed for some licenses: MIT, BSD*")
                    .takes_value(true),
            )
            .arg(
                Arg::with_name("license")
                    .short("l")
                    .long("license")
                    .value_name("NAME")
                    .help( "License to be used")
                    .takes_value(true),
            ))
        .subcommand(SubCommand::with_name("install").about("Installs liftoff files"))
        .subcommand(SubCommand::with_name("uninstall").about("Uninstalls liftoff files"))
        .subcommand(SubCommand::with_name("prep")
            .about("Prepare template file")
            .arg(
                Arg::with_name("identifier")
                    .value_name("NAME")
                    .required(true)
                    .takes_value(true),
            )
            .arg(
                Arg::with_name("name")
                    .short("-n")
                    .long("--name")
                    .value_name("FILENAME")
                    .help( "File will be copied to <FILENAME>")
                    .required(true)
                    .takes_value(true),
            ))
        .subcommand(SubCommand::with_name("save")
            .about("Save customized template file")
            .arg(
                Arg::with_name("name")
                    .value_name("NAME")
                    .required(true)
                    .takes_value(true),
            )
            .arg(
                Arg::with_name("force")
                    .short("f")
                    .long("force")
                    .help("Force overwrite default config file"),
            ))
        .get_matches();

    if matches.subcommand_matches("install").is_some() {
        if let Err(e) = util::install() {
            pexit!(e);
        }
        return;
    }

    if matches.subcommand_matches("uninstall").is_some() {
        if let Err(e) = util::uninstall() {
            pexit!(e);
        }
        return;
    }

    if let Some(ref matches) = matches.subcommand_matches("prep") {
        if let Err(e) = util::prep(&matches) {
            pexit!(e);
        }
        return;
    }

    if let Some(ref matches) = matches.subcommand_matches("save") {
        if let Err(e) = util::save(&matches) {
            pexit!(e);
        }
        return;
    }

    if !Path::exists(Path::new(consts::LIFTOFF_HOME)) {
        pexit!("liftoff not installed. Please install by running 'liftoff install'.");
    }

    if let Some(matches) = &matches.subcommand_matches("new") {
        match util::config_path_from_input(matches) {
            Err(e) => pexit!(e),
            Ok(file_path) => {
                let content = fs::read_to_string(file_path).unwrap(); // safe because of util::path_from_input

                match config::Config::from_args(&content, matches) {
                    Err(e) => pexit!(e),
                    Ok(mut decoded_config) => {
                        if let Err(e) = decoded_config.build() {
                            pexit!(e);
                        }
                    },
                }
            }
        }
    } else {
        panic!("Invalid cl args");
    }
}