From 71d1744d9b60d6c485f67687a65dad554a8e5995 Mon Sep 17 00:00:00 2001 From: aaron-jack-manning Date: Wed, 24 Aug 2022 20:38:47 +1000 Subject: [PATCH] svn integration --- Cargo.lock | 2 +- README.md | 1 - src/main.rs | 17 +++++++++++++---- src/{git.rs => vcs.rs} | 16 ++++++++++------ 4 files changed, 24 insertions(+), 12 deletions(-) rename src/{git.rs => vcs.rs} (51%) diff --git a/Cargo.lock b/Cargo.lock index 219ff8a..47dd664 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -825,7 +825,7 @@ dependencies = [ [[package]] name = "toru" -version = "0.1.1" +version = "0.1.2" dependencies = [ "chrono", "clap", diff --git a/README.md b/README.md index c69e615..632746a 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,6 @@ Then you can run `toru new` to create your first task. - Keep track of completed date, and correctly update upon marking as complete or manual edit - Disallow removing it in a manual edit unless complete is also marked to false - Add to statistics -- SVN integration - Statistics - Completed tasks over last x days - Improve formatting to terminal to make easier to read for `tracked` command diff --git a/src/main.rs b/src/main.rs index 901c086..c647588 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -mod git; +mod vcs; mod edit; mod vault; mod error; @@ -64,6 +64,11 @@ enum Command { Git { args : Vec, }, + /// Run Subversion commands at the root of the vault. + #[clap(trailing_var_arg=true)] + Svn { + args : Vec, + }, /// Adds the recommended .gitignore file to the vault. #[clap(name="gitignore")] GitIgnore, @@ -216,13 +221,17 @@ fn program() -> Result<(), error::Error> { } else if let Git { args } = command { let vault_folder = &config.current_vault()?.1; - git::run_command(args, vault_folder)?; + vcs::command(args, vcs::Vcs::Git, vault_folder)?; } else if command == GitIgnore { let vault_folder = &config.current_vault()?.1; - git::create_gitignore(vault_folder)?; + vcs::create_gitignore(vault_folder)?; println!("Default .gitignore file created"); } + else if let Svn { args } = command { + let vault_folder = &config.current_vault()?.1; + vcs::command(args, vcs::Vcs::Svn, vault_folder)?; + } // Commands that require loading in the state. else { let vault_folder = &config.current_vault()?.1; @@ -294,7 +303,7 @@ fn program() -> Result<(), error::Error> { println!("Deleted all discarded tasks"); } // All commands which are dealt with in if let chain at start. - Vault(_) | Config(_) | Git { args : _ } | Switch { name : _ } | GitIgnore => unreachable!(), + Vault(_) | Config(_) | Git { args : _ } | Svn { args : _ } | Switch { name : _ } | GitIgnore => unreachable!(), } state.save()?; diff --git a/src/git.rs b/src/vcs.rs similarity index 51% rename from src/git.rs rename to src/vcs.rs index c759a9a..3f43e80 100644 --- a/src/git.rs +++ b/src/vcs.rs @@ -4,19 +4,23 @@ use std::fs; use std::path; use std::process; -pub fn run_command(args : Vec, vault_folder : &path::Path) -> Result<(), error::Error> { +pub enum Vcs { + Git, + Svn, +} - let mut command = process::Command::new("git"); +pub fn command(args : Vec, vcs : Vcs, vault_folder : &path::Path) -> Result<(), error::Error> { + + let mut command = match vcs { + Vcs::Git => process::Command::new("git"), + Vcs::Svn => process::Command::new("svn"), + }; let mut child = command .current_dir(vault_folder) - // Force colour output even though run from other process. - .args(["-c", "color.ui=always"]) .args(args) .spawn()?; - // No point handling the potential error code as Git will report the error directly with more - // info. let _ = child.wait()?; Ok(())