commit 885af1cfb3f5356c1968e5c31677835ecdfd2a25
parent fd13eee0267cb4ad276771596e73f18e5113acab
Author: cy6erlion <50733658+cy6erlion@users.noreply.github.com>
Date: Thu, 31 Dec 2020 21:21:21 +0200
Merge pull request #3 from 0xflotus/clean
feat: remove rfcs from disk
Diffstat:
2 files changed, 62 insertions(+), 0 deletions(-)
diff --git a/src/lib.rs b/src/lib.rs
@@ -85,6 +85,44 @@ 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) {
+ 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
@@ -12,7 +12,16 @@ 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();
// Read RFC by serial number
@@ -24,12 +33,27 @@ 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();
return;
}
+ // Remove the ietf directory
+ if let Some(_matches) = matches.subcommand_matches("clean") {
+ ietf::clean();
+ return;
+ }
+
// Display RFC list view
ietf::list_view();
}