43 lines
981 B
Rust
43 lines
981 B
Rust
use crate::subcommands::{
|
|
add::AddSubcommand, hash_object::HashObjectSubcommand, init::InitSubcommand, rm::RmSubcommand,
|
|
test::TestSubcommand,
|
|
};
|
|
use anyhow::Result;
|
|
use clap::Subcommand;
|
|
|
|
mod add;
|
|
mod hash_object;
|
|
mod init;
|
|
mod rm;
|
|
mod test;
|
|
|
|
#[derive(Debug, Subcommand)]
|
|
pub enum SubcommandType {
|
|
/// Add file(s) to index
|
|
Add(AddSubcommand),
|
|
/// Remove file(s) from the index
|
|
Rm(RmSubcommand),
|
|
/// Init a Git repository
|
|
Init(InitSubcommand),
|
|
#[clap(hide = true)]
|
|
HashObject(HashObjectSubcommand),
|
|
#[clap(hide = true)]
|
|
Test(TestSubcommand),
|
|
}
|
|
|
|
pub trait GitSubcommand {
|
|
fn run(&self) -> Result<()>;
|
|
}
|
|
|
|
impl GitSubcommand for SubcommandType {
|
|
fn run(&self) -> Result<()> {
|
|
match self {
|
|
Self::Add(cmd) => cmd.run(),
|
|
Self::Rm(cmd) => cmd.run(),
|
|
Self::Init(cmd) => cmd.run(),
|
|
Self::HashObject(cmd) => cmd.run(),
|
|
Self::Test(cmd) => cmd.run(),
|
|
}
|
|
}
|
|
}
|