Index parsing and gitignore files

This commit is contained in:
Antonin Ruan
2026-03-11 17:49:08 +01:00
parent f600a89f5b
commit 3027a99b5f
13 changed files with 1072 additions and 268 deletions
+13 -7
View File
@@ -1,17 +1,21 @@
use crate::subcommands::{
init::InitSubcommand,
test::TestSubcommand,
hash_object::HashObjectSubcommand,
add::AddSubcommand, hash_object::HashObjectSubcommand, init::InitSubcommand,
remove::RemoveSubcommand, test::TestSubcommand,
};
use anyhow::Result;
mod add;
mod hash_object;
mod init;
mod remove;
mod test;
pub type CmdResult = Result<String, String>;
#[derive(clap::Parser, Debug)]
pub enum SubcommandType {
/// Add file(s) to index
Add(AddSubcommand),
/// Remove file from the working and the index
Remove(RemoveSubcommand),
/// Init a Git repository
Init(InitSubcommand),
HashObject(HashObjectSubcommand),
@@ -19,12 +23,14 @@ pub enum SubcommandType {
}
pub trait Subcommand {
fn run(&self) -> CmdResult;
fn run(&self) -> Result<String>;
}
impl Subcommand for SubcommandType {
fn run(&self) -> CmdResult {
fn run(&self) -> Result<String> {
match self {
Self::Add(cmd) => cmd.run(),
Self::Remove(cmd) => cmd.run(),
Self::Init(cmd) => cmd.run(),
Self::HashObject(cmd) => cmd.run(),
Self::Test(cmd) => cmd.run(),