bulk 0.4.2

A simple tool for making deb packages, repositories, and update version numbers.
extern crate quire;
extern crate argparse;
extern crate tar;
extern crate scan_dir;
extern crate rustc_serialize;
extern crate sha2;
extern crate time;
extern crate flate2;
extern crate regex;
extern crate unicase;
extern crate env_logger;
#[macro_use] extern crate log;
#[macro_use] extern crate matches;
#[macro_use] extern crate lazy_static;
#[macro_use] extern crate quick_error;


mod config;
mod deb_ext;
mod hash_file;
mod version;
mod bulk_version;
mod re;

mod repo;
mod pack;
mod ver;

use std::str::FromStr;

use argparse::{ArgumentParser, Store, Print, List};


enum Action {
    Help,
    Pack,
    RepoAdd,
    GetVersion,
    SetVersion,
    CheckVersion,
    WithVersion,
}

impl FromStr for Action {
    type Err = ();
    fn from_str(value: &str) -> Result<Action, ()> {
        match value {
            "help" => Ok(Action::Help),

            "pack" => Ok(Action::Pack),

            "repo-add" => Ok(Action::RepoAdd),
            "repo_add" => Ok(Action::RepoAdd),
            "repoadd" => Ok(Action::RepoAdd),
            "radd" => Ok(Action::RepoAdd),
            "add-to-repo" => Ok(Action::RepoAdd),
            "add_to_repo" => Ok(Action::RepoAdd),
            "addtorepo" => Ok(Action::RepoAdd),

            "getversion" => Ok(Action::GetVersion),
            "get-version" => Ok(Action::GetVersion),
            "getver" => Ok(Action::GetVersion),
            "get-ver" => Ok(Action::GetVersion),
            "ver-get" => Ok(Action::GetVersion),
            "version-get" => Ok(Action::GetVersion),
            "verget" => Ok(Action::GetVersion),
            "versionget" => Ok(Action::GetVersion),

            "set-version" => Ok(Action::SetVersion),
            "set-ver" => Ok(Action::SetVersion),
            "setversion" => Ok(Action::SetVersion),
            "setver" => Ok(Action::SetVersion),
            "ver-set" => Ok(Action::SetVersion),
            "version-set" => Ok(Action::SetVersion),
            "verset" => Ok(Action::SetVersion),
            "versionset" => Ok(Action::SetVersion),

            "check-version" => Ok(Action::CheckVersion),
            "version-check" => Ok(Action::CheckVersion),

            "with-version" => Ok(Action::WithVersion),

            _ => Err(())
        }
    }
}


fn main() {
    let mut command = Action::Help;
    let mut args = Vec::<String>::new();
    {
        let mut ap = ArgumentParser::new();
        ap.add_option(&["-V", "--version"],
            Print(env!("CARGO_PKG_VERSION").to_string()),
            "Show version of bulk and exit");
        ap.refer(&mut command)
            .add_argument("command", Store, "
                Command to run. Supported commands: \
                pack, repo-add, get-version, set-version, check-version, \
                with-version");
        ap.refer(&mut args)
            .add_argument("arguments", List,
                "Arguments for the command");
        ap.stop_on_first_argument(true);
        ap.parse_args_or_exit();
    }
    env_logger::init().expect("init logging system");
    match command {
        Action::Help => {
            println!("Usage:");
            println!("    bulk \
                {{pack,repo-add,get-version,set-verion,\
                  check-version,with-version}} \
                [options]");
        }
        Action::Pack => {
            args.insert(0, "bulk pack".to_string());
            pack::pack(args);
        }
        Action::RepoAdd => {
            args.insert(0, "bulk repo-add".to_string());
            repo::repo_add(args);
        }
        Action::GetVersion => {
            args.insert(0, "bulk get-version".to_string());
            ver::get_version(args);
        }
        Action::SetVersion => {
            args.insert(0, "bulk set-version".to_string());
            ver::set_version(args);
        }
        Action::CheckVersion => {
            args.insert(0, "bulk check-version".to_string());
            ver::check_version(args);
        }
        Action::WithVersion => {
            args.insert(0, "bulk with-version".to_string());
            ver::with_version(args);
        }
    }
}