From 1a1b98729a60aef1090347dc1b9f55d8b34dcf69 Mon Sep 17 00:00:00 2001 From: grimhilt Date: Sat, 3 Jun 2023 17:37:23 +0200 Subject: [PATCH] reset command --- src/commands.rs | 1 + src/commands/reset.rs | 17 +++++++++++++++++ src/main.rs | 3 +++ 3 files changed, 21 insertions(+) create mode 100644 src/commands/reset.rs diff --git a/src/commands.rs b/src/commands.rs index 18af971..5066f6a 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -1,3 +1,4 @@ pub mod init; pub mod status; pub mod add; +pub mod reset; diff --git a/src/commands/reset.rs b/src/commands/reset.rs new file mode 100644 index 0000000..dd4ee84 --- /dev/null +++ b/src/commands/reset.rs @@ -0,0 +1,17 @@ +use std::fs::File; +use crate::utils; + +pub fn reset() { + let mut root = match utils::path::nextsync_root() { + Some(path) => path, + None => { + eprintln!("fatal: not a nextsync repository (or any of the parent directories): .nextsync"); + std::process::exit(1); + } + }; + root.push(".nextsync"); + root.push("index"); + if File::create(root).is_err() { + eprintln!("fatal: failed to reset"); + } +} diff --git a/src/main.rs b/src/main.rs index c89c956..ad9ef90 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,6 +16,7 @@ fn main() { .about("") .subcommand(SubCommand::with_name("init")) .subcommand(SubCommand::with_name("status")) + .subcommand(SubCommand::with_name("reset")) .subcommand( SubCommand::with_name("add") .arg( @@ -37,6 +38,8 @@ fn main() { if let Some(files) = matches.values_of("files") { commands::add::add(files); } + } else if let Some(_) = matches.subcommand_matches("reset") { + commands::reset::reset(); }