diff options
author | Justin Wernick <justin@worthe-it.co.za> | 2023-06-24 21:52:37 +0200 |
---|---|---|
committer | Justin Wernick <justin@worthe-it.co.za> | 2023-06-24 21:52:37 +0200 |
commit | da8802d1fb0c5707877777ff4187238195eef16b (patch) | |
tree | 60b6d9ca408d252c2f6e96b1c90a3993c3f0dc39 /src | |
parent | 20ff259800f3a5568c53fca3992c4e062282b82a (diff) |
Added a command to delete a repo
Diffstat (limited to 'src')
-rw-r--r-- | src/git.rs | 13 | ||||
-rw-r--r-- | src/lib.rs | 4 | ||||
-rw-r--r-- | src/parser.rs | 9 |
3 files changed, 26 insertions, 0 deletions
@@ -194,6 +194,19 @@ pub fn set_branch(directory: &Path, branch: &str) -> Result<(), ShackleError> { } } +pub fn delete(directory: &Path) -> Result<(), ShackleError> { + if !is_valid_git_repo_path(directory)? { + return Err(ShackleError::InvalidDirectory); + } + + if Repository::open_bare(directory).is_ok() { + fs::remove_dir_all(directory)?; + Ok(()) + } else { + Err(ShackleError::InvalidDirectory) + } +} + pub fn upload_pack(upload_pack_args: &GitUploadPackArgs) -> Result<(), ShackleError> { if !is_valid_git_repo_path(&upload_pack_args.directory)? { return Err(ShackleError::InvalidDirectory); @@ -46,6 +46,10 @@ pub fn run_command(user_input: &str) -> Result<ControlFlow<(), ()>, ShackleError let init_result = git::init(&repo_name, &group, &description, &branch)?; println!("Successfully created \"{}\"", init_result.path.display()); } + Ok(ShackleCommand::Delete(DeleteArgs { directory })) => { + git::delete(&directory)?; + println!("Successfully deleted \"{}\"", directory.display()); + } Ok(ShackleCommand::GitUploadPack(upload_pack_args)) => { git::upload_pack(&upload_pack_args)?; } diff --git a/src/parser.rs b/src/parser.rs index ebd860b..30eb1e0 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -16,6 +16,8 @@ pub enum ShackleCommand { SetDescription(SetDescriptionArgs), /// Sets the main branch of the repository SetBranch(SetBranchArgs), + /// Deletes a repository + Delete(DeleteArgs), /// Quit the shell Exit, /// Server side command required to git fetch from the server @@ -58,6 +60,13 @@ pub struct SetBranchArgs { } #[derive(Parser, Clone, Debug, PartialEq, Eq)] +pub struct DeleteArgs { + /// The full relative path of the repository, for example git/shuckie/repo.git + #[arg(value_parser = RelativePathParser)] + pub directory: PathBuf, +} + +#[derive(Parser, Clone, Debug, PartialEq, Eq)] pub struct GitUploadPackArgs { /// Do not try <directory>/.git/ if <directory> is no Git directory #[arg(long, default_value_t = true)] |