36 lines
862 B
Rust
36 lines
862 B
Rust
|
use anyhow::Result;
|
||
|
|
||
|
use structopt::StructOpt;
|
||
|
|
||
|
macro_rules! define_commands {
|
||
|
($(($name:expr, $cmd_fn:ident, $cmd_variant:ident, $opt_struct:ident),)*) => {
|
||
|
#[derive(Debug, StructOpt)]
|
||
|
enum Command {
|
||
|
$(
|
||
|
#[structopt(name = $name)]
|
||
|
$cmd_variant(async_git::porcelain::$opt_struct),
|
||
|
)*
|
||
|
}
|
||
|
|
||
|
async fn handle_command(cmd: Command) -> Result<()> {
|
||
|
match cmd {
|
||
|
$(
|
||
|
Command::$cmd_variant(options) => async_git::porcelain::$cmd_fn(options).await?,
|
||
|
)*
|
||
|
};
|
||
|
Ok(())
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
|
||
|
define_commands!(
|
||
|
("init", init_cmd, Init, InitOptions),
|
||
|
("log", log_cmd, Log, LogOptions),
|
||
|
);
|
||
|
|
||
|
#[tokio::main]
|
||
|
async fn main() -> Result<()> {
|
||
|
handle_command(Command::from_args()).await?;
|
||
|
Ok(())
|
||
|
}
|