ietf

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

commit a2cd903afdd43c5fe5acde6610db8c2d234e652d
parent 08aa5644650d91480615b49bbeeb8f435e000e92
Author: 0xflotus <0xflotus@gmail.com>
Date:   Thu, 31 Dec 2020 01:46:35 +0100

feat: remove rfc by serial number

Diffstat:
Msrc/lib.rs | 20++++++++++++++++++++
Msrc/main.rs | 17+++++++++++++++++
2 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/src/lib.rs b/src/lib.rs @@ -85,6 +85,26 @@ pub fn update() { fetch::index().unwrap(); } +// Removes RFC by Serial Number +pub fn remove(sn: u32) { + if let Some(home_path) = dirs_next::home_dir() { + let path = if cfg!(unix) || cfg!(macos) { + format!("{}/rfc/{}", home_path.to_str().unwrap(), sn) + } else if cfg!(windows) { + format!("{}\\rfc\\{}", home_path.to_str().unwrap(), sn) + } else { + panic!("Unsupported OS"); + }; + + if Path::new(&path).exists() { + std::fs::remove_file(&path).unwrap(); + } + } else { + panic!("Could not find home directory"); + } +} + +// Removes the rfc directory pub fn clean() -> () { if let Some(home_path) = dirs_next::home_dir() { let path = if cfg!(unix) || cfg!(macos) { diff --git a/src/main.rs b/src/main.rs @@ -12,6 +12,14 @@ fn main() { .help("RFC Serial Number") .takes_value(true), ) + .arg( + Arg::with_name("Remove") + .short("r") + .long("remove") + .value_name("serial") + .help("RFC Serial Number") + .takes_value(true), + ) .subcommand(SubCommand::with_name("update").about("Update RFC Index")) .subcommand(SubCommand::with_name("clean").about("Remove the rfc directory")) .get_matches(); @@ -25,6 +33,15 @@ fn main() { return; } + // Removes RFC by serial number + if let Some(n) = matches.value_of("Remove") { + ietf::remove( + n.parse::<u32>() + .expect("RFC Serial Number should be a numeric value!"), + ); + return; + } + // Update RFC index if let Some(_matches) = matches.subcommand_matches("update") { ietf::update();