From f43d583ae61d18d551dda69810cebf0a125551a9 Mon Sep 17 00:00:00 2001 From: aaron-jack-manning Date: Mon, 22 Aug 2022 18:51:54 +1000 Subject: [PATCH] gitignore creation command --- README.md | 2 -- src/git.rs | 5 +++++ src/main.rs | 16 ++++++++++++---- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 410e2f0..73269d2 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,4 @@ Run `--help` alongside any command to get details on what it does. - Due dates - Taken as input when creating notes - Displayed in list view by default (with number of days remaining) -- Git integration - - Command to add default gitignore file - `clean` command to delete discarded tasks diff --git a/src/git.rs b/src/git.rs index 7904960..c759a9a 100644 --- a/src/git.rs +++ b/src/git.rs @@ -1,5 +1,6 @@ use crate::error; +use std::fs; use std::path; use std::process; @@ -20,3 +21,7 @@ pub fn run_command(args : Vec, vault_folder : &path::Path) -> Result<(), Ok(()) } + +pub fn create_gitignore(vault_folder : &path::Path) -> Result<(), error::Error> { + Ok(fs::write(vault_folder.join(".gitignore"), "state.toml\ntemp.toml\ntemp.md")?) +} diff --git a/src/main.rs b/src/main.rs index 96b66af..0f01b06 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,7 +17,7 @@ struct Args { command : Command, } -#[derive(clap::Subcommand, Debug)] +#[derive(clap::Subcommand, Debug, PartialEq, Eq)] #[clap(version, about, author, global_setting=clap::AppSettings::DisableHelpSubcommand)] enum Command { /// Create a new task. @@ -61,6 +61,9 @@ enum Command { Git { args : Vec, }, + /// Adds the recommended .gitignore file to the vault. + #[clap(name="gitignore")] + GitIgnore, /// Lists tasks according to the specified ordering and filters. List { // Need to have options for: @@ -81,7 +84,7 @@ enum Command { }, } -#[derive(clap::Subcommand, Debug)] +#[derive(clap::Subcommand, Debug, PartialEq, Eq)] enum ConfigCommand { /// For checking or changing default text editor command. Editor { @@ -90,7 +93,7 @@ enum ConfigCommand { } } -#[derive(clap::Subcommand, Debug)] +#[derive(clap::Subcommand, Debug, PartialEq, Eq)] enum VaultCommand { /// Creates a new vault at the specified location of the given name. New { @@ -183,6 +186,11 @@ fn program() -> Result<(), error::Error> { let vault_folder = &config.current_vault()?.1; git::run_command(args, vault_folder)?; } + else if command == GitIgnore { + let vault_folder = &config.current_vault()?.1; + git::create_gitignore(vault_folder)?; + println!("Default .gitignore file created"); + } // Commands that require loading in the state. else { let vault_folder = &config.current_vault()?.1; @@ -235,7 +243,7 @@ fn program() -> Result<(), error::Error> { tasks::list(vault_folder)?; }, // All commands which are dealt with in if let chain at start. - Vault(_) | Config(_) | Git { args : _ } | Switch { name : _ } => unreachable!(), + Vault(_) | Config(_) | Git { args : _ } | Switch { name : _ } | GitIgnore => unreachable!(), } state.save()?;