37 lines
1017 B
Rust
37 lines
1017 B
Rust
#[macro_use] extern crate rust_util;
|
|
|
|
mod cmd;
|
|
mod cmd_default;
|
|
mod cmd_crate;
|
|
mod cmd_gitcheck;
|
|
mod cmd_sample;
|
|
|
|
use std::process;
|
|
use clap::App;
|
|
use cmd::Command;
|
|
use rust_util::XResult;
|
|
|
|
fn main() -> XResult<()> {
|
|
let commands: Vec<Box<dyn Command>> = vec![
|
|
Box::new(cmd_sample::CommandImpl),
|
|
Box::new(cmd_crate::CommandImpl),
|
|
Box::new(cmd_gitcheck::CommandImpl),
|
|
];
|
|
let mut app = App::new(env!("CARGO_PKG_NAME"))
|
|
.version(env!("CARGO_PKG_VERSION"))
|
|
.about(env!("CARGO_PKG_DESCRIPTION"));
|
|
app = cmd_default::CommandImpl::process_command(app);
|
|
for command in &commands {
|
|
app = app.subcommand(command.subcommand());
|
|
}
|
|
|
|
let matches = app.get_matches();
|
|
for command in &commands {
|
|
if let Some(sub_cmd_matches) = matches.subcommand_matches(command.name()) {
|
|
process::exit( command.run(&matches, sub_cmd_matches)?);
|
|
}
|
|
}
|
|
|
|
process::exit(cmd_default::CommandImpl::run(&matches)?);
|
|
}
|