git integration

This commit is contained in:
aaron-jack-manning 2022-08-20 17:06:55 +10:00
parent 261aa74800
commit 1cc7adfeb8
4 changed files with 48 additions and 3 deletions

View File

@ -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<String, Vec<Id>>`
- 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

View File

@ -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<toml::ser::Error> for Error {
Error::TomlSer(err)
}
}
impl From<str::Utf8Error> for Error {
fn from(err : str::Utf8Error) -> Self {
Error::Utf8(err)
}
}

26
src/git.rs Normal file
View File

@ -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<String>, 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(())
}

View File

@ -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<String>,
},
/// 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!(),
}