1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
use structopt::StructOpt;
use std::path::PathBuf;

macro_rules! subcommands {
    ($($ident:ident),* $(,)?) => {
        $(
            mod $ident;
            pub use $ident::*;
        )*
    };
}

subcommands!{
    new,
    build,
    install,
    run,
}

pub use build::SYMBOLS_PROPER_NAMES;

mod error;
pub use error::Error;

pub mod iso;
pub mod paths;
pub mod manifest;

#[derive(StructOpt)]
#[structopt(bin_name = "cargo")]
pub enum Args {
    Mextk(SubCommands),
}

#[derive(StructOpt)]
pub enum SubCommands {
    #[structopt(about = "Create a new mod from the mextk template")]
    New {
        name: String,
    },
    
    #[structopt(about = "Build the current crate targetting MexTK")]
    Build {
        #[structopt(long)]
        debug: bool,
    },
    
    #[structopt(about = "Run the current crate targetting MexTK")]
    Run {
        #[structopt(long)]
        debug: bool,

        #[structopt(long)]
        no_restore: bool,
    },
    
    #[structopt(about = "Add an ISO to be managed")]
    AddIso {
        iso: PathBuf,
    },

    #[structopt(about = "Remove an ISO being managed by its id")]
    RemoveIso {
        id: String,
    },

    #[structopt(about = "List all ISOs being managed")]
    List,
    
    #[structopt(about = "Restore the extracted files for a given managed ISO provided its id")]
    Restore {
        id: String,
    },

    #[structopt(about = "Install the current crate to the mod directory")]
    Install {
        #[structopt(long)]
        restore: bool,
    },
}

pub fn main(args: Args) -> Result<(), Error> {
    let Args::Mextk(command) = args;

    match command {
        SubCommands::New { name } => new(&name),
        SubCommands::Build { debug } => {
            let _output = build(debug)?;

            //println!(
            //    "{}",
            //    format!("Object file built to {}", output.display())
            //        .bright_green()
            //        .bold()
            //);

            Ok(())
        },
        SubCommands::AddIso { iso } => iso::add(&iso, true),
        SubCommands::RemoveIso { id } => iso::remove(&id),
        SubCommands::List => iso::list().map(iso::display_list),
        SubCommands::Run { debug, no_restore } => run(debug, no_restore),
        SubCommands::Restore { id } => iso::restore(&id, true),
        SubCommands::Install { restore } => install(restore),
    }
}