diff --git a/README.md b/README.md index 739d33e..def063e 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,6 @@ A (currently in development) to do app for the command line. - Options for which field to order by, and how to order (ascending or descending) - Options for which columns to include - If no values given, read a set of defaults from a `list.toml` file, which can be edited from a similar command -- Git integration - - `toru git` should run the provided Git command directly at the root of the current vault - Ability to view, edit, delete, etc. using name - Have a file containing a serialized `HashMap>` - Disallow numerical names and have command automatically identify if it is a name or Id @@ -28,3 +26,6 @@ A (currently in development) to do app for the command line. - Error if any circular dependencies are introduced - Make sure dependencies written to file are only those that could be successfully created - Automatically added recurring notes + +## Bugs: +- Git commands which automatically open a text editor after don't work as expected diff --git a/src/error.rs b/src/error.rs index e1c79ae..887285c 100644 --- a/src/error.rs +++ b/src/error.rs @@ -2,6 +2,7 @@ use crate::colour; use std::io; use std::fmt; +use std::str; #[derive(Debug)] pub enum Error { @@ -10,6 +11,7 @@ pub enum Error { Trash(trash::Error), TomlDe(toml::de::Error), TomlSer(toml::ser::Error), + Utf8(str::Utf8Error), Generic(String), } @@ -21,6 +23,7 @@ impl fmt::Display for Error { Error::Trash(err) => write!(f, "{} {}", colour::error("Internal Error:"), err), Error::TomlDe(err) => write!(f, "{} {}", colour::error("Internal Error:"), err), Error::TomlSer(err) => write!(f, "{} {}", colour::error("Internal Error:"), err), + Error::Utf8(err) => write!(f, "{} {}", colour::error("Internal Error:"), err), Error::Generic(message) => write!(f, "{}", message), } } @@ -55,3 +58,9 @@ impl From for Error { Error::TomlSer(err) } } + +impl From for Error { + fn from(err : str::Utf8Error) -> Self { + Error::Utf8(err) + } +} diff --git a/src/git.rs b/src/git.rs new file mode 100644 index 0000000..b1227a7 --- /dev/null +++ b/src/git.rs @@ -0,0 +1,26 @@ +use crate::error; + +use std::io; +use std::str; +use std::path; +use std::process; +use std::io::Write; + +pub fn run_command(args : Vec, vault_folder : &path::Path) -> Result<(), error::Error> { + + let mut command = process::Command::new("git"); + + command + .current_dir(vault_folder) + // Force colour output even though run from other process. + .args(["-c", "color.ui=always"]) + .args(args); + + let output = command.output()?; + let output_string = str::from_utf8(&output.stdout)?; + + print!("{}", output_string); + io::stdout().flush()?; + + Ok(()) +} diff --git a/src/main.rs b/src/main.rs index 765db9c..b9166c9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ #![allow(dead_code, unused_variables)] +mod git; mod vault; mod error; mod tasks; @@ -16,7 +17,7 @@ struct Args { } #[derive(clap::Subcommand, Debug)] -#[clap(version, about, author, global_setting = clap::AppSettings::DisableHelpSubcommand)] +#[clap(version, about, author, global_setting=clap::AppSettings::DisableHelpSubcommand)] enum Command { /// Create a new task. New { @@ -43,6 +44,11 @@ enum Command { Complete { id : tasks::Id, }, + /// Run Git commands at the root of the vault. + #[clap(trailing_var_arg=true)] + Git { + args : Vec, + }, /// Commands for interacting with vaults. #[clap(subcommand)] Vault(VaultCommand), @@ -151,6 +157,9 @@ fn program() -> Result<(), error::Error> { task.save()?; println!("Marked task {} as complete", colour::id(&id.to_string())); }, + Git { args } => { + git::run_command(args, vault_folder)?; + }, Vault(_) => unreachable!(), }