refactor subcommand behavior
This commit is contained in:
@@ -3,6 +3,7 @@ use crate::subcommands::{
|
||||
test::TestSubcommand,
|
||||
};
|
||||
use anyhow::Result;
|
||||
use clap::Subcommand;
|
||||
|
||||
mod add;
|
||||
mod hash_object;
|
||||
@@ -10,7 +11,7 @@ mod init;
|
||||
mod rm;
|
||||
mod test;
|
||||
|
||||
#[derive(clap::Parser, Debug)]
|
||||
#[derive(Debug, Subcommand)]
|
||||
pub enum SubcommandType {
|
||||
/// Add file(s) to index
|
||||
Add(AddSubcommand),
|
||||
@@ -18,16 +19,18 @@ pub enum SubcommandType {
|
||||
Rm(RmSubcommand),
|
||||
/// Init a Git repository
|
||||
Init(InitSubcommand),
|
||||
#[clap(hide = true)]
|
||||
HashObject(HashObjectSubcommand),
|
||||
#[clap(hide = true)]
|
||||
Test(TestSubcommand),
|
||||
}
|
||||
|
||||
pub trait Subcommand {
|
||||
fn run(&self) -> Result<String>;
|
||||
pub trait GitSubcommand {
|
||||
fn run(&self) -> Result<()>;
|
||||
}
|
||||
|
||||
impl Subcommand for SubcommandType {
|
||||
fn run(&self) -> Result<String> {
|
||||
impl GitSubcommand for SubcommandType {
|
||||
fn run(&self) -> Result<()> {
|
||||
match self {
|
||||
Self::Add(cmd) => cmd.run(),
|
||||
Self::Rm(cmd) => cmd.run(),
|
||||
|
||||
Reference in New Issue
Block a user