commit ce5601f42a5191ea3320d996c1696de7886b8b7d
parent 82246d5972ddc33a9ec57486d1ea623763a5a301
Author: cy6erlion <dev@merely.tech>
Date: Tue, 12 Jan 2021 11:53:16 +0200
remove lib.rs
Diffstat:
M | README.md | | | 26 | ++++++++++++-------------- |
A | src/lib.rs | | | 77 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 files changed, 89 insertions(+), 14 deletions(-)
diff --git a/README.md b/README.md
@@ -1,29 +1,27 @@
-``` text
+``` console
██▄██ ▄▄█▄ ▄█ ▄▄
██ ▄█ ▄▄██ ██ ▄█
█▄▄▄█▄▄▄██▄██▄██
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
-```
-
-``` bash
-$ ietf -h
ietf 0.1.0
A program to read RFCs in the terminal.
USAGE:
- ietf [OPTIONS] [SUBCOMMAND]
-
+ ietf [OPTIONS] [SUBCOMMAND]
+
FLAGS:
- -h, --help Prints help information
- -V, --version Prints version information
-
+ -h, --help Prints help information
+ -V, --version Prints version information
+
OPTIONS:
- -n, --number <serial> RFC Serial Number
-
+ -n, --number <serial> RFC Serial Number
+ -r, --remove <serial> RFC Serial Number
+
SUBCOMMANDS:
- help Prints this message or the help of the given subcommand(s)
- update Update RFC Index
+ clean Remove the rfc directory
+ help Prints this message or the help of the given subcommand(s)
+ update Update RFC Index
```
## Features
diff --git a/src/lib.rs b/src/lib.rs
@@ -0,0 +1,77 @@
+extern crate dirs_next;
+extern crate pager;
+
+use pager::Pager;
+use std::fs::File;
+use std::io::{BufReader, Read};
+
+mod fetch;
+pub mod storage;
+
+pub fn list_view() {
+ if !storage::index_exists().unwrap() {
+ // Download all RFCs
+ fetch::index().unwrap();
+ }
+
+ let home_path = if let Some(p) = storage::get_home_path() {
+ p
+ } else {
+ panic!("Error: 'Could not find home directory!'");
+ };
+
+ let path = format!("{}INDEX", home_path);
+
+ let mut index = String::new();
+ let f = File::open(&path).expect("Unable to open file");
+ let mut br = BufReader::new(f);
+ let mut dots = "";
+
+ br.read_to_string(&mut index).expect("Unable to read INDEX");
+
+ Pager::with_pager("less -r").setup();
+
+ for line in index.lines() {
+ let line_words: Vec<&str> = line.split(' ').collect();
+ let summerize: String = line.chars().skip(line_words[0].len()).take(77).collect();
+
+ if line.len() >= 77 {
+ dots = "...";
+ }
+
+ println!("{} | {}{}", line_words[0], summerize, dots);
+
+ dots = "";
+ }
+}
+
+// Read RFC by serial number
+pub fn read_rfc(rfc_number: u32) {
+ // check if RFC is downloaded
+ if !storage::is_rfc_downloaded(rfc_number).unwrap() {
+ // download RFC
+ fetch::rfc(rfc_number).unwrap();
+ }
+
+ let home_path = if let Some(p) = storage::get_home_path() {
+ p
+ } else {
+ panic!("Error: 'Could not find home directory!'");
+ };
+
+ let path = format!("{}{}", home_path, rfc_number);
+
+ let mut rfc = String::new();
+ let f = File::open(&path).expect("Unable to open file");
+ let mut br = BufReader::new(f);
+ br.read_to_string(&mut rfc).expect("Unable to read RFC");
+
+ // Read RFC
+ Pager::with_pager("less -r").setup();
+ println!("{}", &rfc);
+}
+
+// Update RFC
+pub fn update() {
+ fetch::index().unwrap();
+}