cargo_mextk/
lib.rs

1use structopt::StructOpt;
2use std::path::PathBuf;
3
4macro_rules! subcommands {
5    ($($ident:ident),* $(,)?) => {
6        $(
7            mod $ident;
8            pub use $ident::*;
9        )*
10    };
11}
12
13subcommands!{
14    new,
15    build,
16    install,
17    run,
18}
19
20pub use build::SYMBOLS_PROPER_NAMES;
21
22mod error;
23pub use error::Error;
24
25pub mod iso;
26pub mod paths;
27pub mod manifest;
28
29#[derive(StructOpt)]
30#[structopt(bin_name = "cargo")]
31pub enum Args {
32    Mextk(SubCommands),
33}
34
35#[derive(StructOpt)]
36pub enum SubCommands {
37    #[structopt(about = "Create a new mod from the mextk template")]
38    New {
39        name: String,
40    },
41    
42    #[structopt(about = "Build the current crate targetting MexTK")]
43    Build {
44        #[structopt(long)]
45        debug: bool,
46    },
47    
48    #[structopt(about = "Run the current crate targetting MexTK")]
49    Run {
50        #[structopt(long)]
51        debug: bool,
52
53        #[structopt(long)]
54        no_restore: bool,
55    },
56    
57    #[structopt(about = "Add an ISO to be managed")]
58    AddIso {
59        iso: PathBuf,
60    },
61
62    #[structopt(about = "Remove an ISO being managed by its id")]
63    RemoveIso {
64        id: String,
65    },
66
67    #[structopt(about = "List all ISOs being managed")]
68    List,
69    
70    #[structopt(about = "Restore the extracted files for a given managed ISO provided its id")]
71    Restore {
72        id: String,
73    },
74
75    #[structopt(about = "Install the current crate to the mod directory")]
76    Install {
77        #[structopt(long)]
78        restore: bool,
79    },
80}
81
82pub fn main(args: Args) -> Result<(), Error> {
83    let Args::Mextk(command) = args;
84
85    match command {
86        SubCommands::New { name } => new(&name),
87        SubCommands::Build { debug } => {
88            let _output = build(debug)?;
89
90            //println!(
91            //    "{}",
92            //    format!("Object file built to {}", output.display())
93            //        .bright_green()
94            //        .bold()
95            //);
96
97            Ok(())
98        },
99        SubCommands::AddIso { iso } => iso::add(&iso, true),
100        SubCommands::RemoveIso { id } => iso::remove(&id),
101        SubCommands::List => iso::list().map(iso::display_list),
102        SubCommands::Run { debug, no_restore } => run(debug, no_restore),
103        SubCommands::Restore { id } => iso::restore(&id, true),
104        SubCommands::Install { restore } => install(restore),
105    }
106}