ietf

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit b8e61be68b58c6607a4e717d1307f9c123ed714f
parent fd13eee0267cb4ad276771596e73f18e5113acab
Author: 0xflotus <0xflotus@gmail.com>
Date:   Thu, 31 Dec 2020 01:34:53 +0100

feat: added clean subommand

Diffstat:
Msrc/lib.rs | 18++++++++++++++++++
Msrc/main.rs | 7+++++++
2 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/src/lib.rs b/src/lib.rs @@ -85,6 +85,24 @@ pub fn update() { fetch::index().unwrap(); } +pub fn clean() -> () { + if let Some(home_path) = dirs_next::home_dir() { + let path = if cfg!(unix) || cfg!(macos) { + format!("{}/rfc", home_path.to_str().unwrap()) + } else if cfg!(windows) { + format!("{}\\rfc", home_path.to_str().unwrap()) + } else { + panic!("Unsupported OS"); + }; + + if Path::new(&path).exists() { + std::fs::remove_dir_all(&path).unwrap(); + } + } else { + panic!("Could not find home directory"); + } +} + // Check if it is first time running by // checking if config files exist fn index_exists() -> Result<bool, ()> { diff --git a/src/main.rs b/src/main.rs @@ -13,6 +13,7 @@ fn main() { .takes_value(true), ) .subcommand(SubCommand::with_name("update").about("Update RFC Index")) + .subcommand(SubCommand::with_name("clean").about("Remove the ietf directory")) .get_matches(); // Read RFC by serial number @@ -30,6 +31,12 @@ fn main() { return; } + // Remove the ietf directory + if let Some(_matches) = matches.subcommand_matches("clean") { + ietf::clean(); + return; + } + // Display RFC list view ietf::list_view(); }