adding help comand

This commit is contained in:
talksik
2023-06-02 11:27:07 -07:00
parent fccd8cf4ae
commit b411341375
4 changed files with 31 additions and 21 deletions
Generated
+10 -10
View File
@@ -689,6 +689,16 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54"
[[package]]
name = "news"
version = "0.1.0"
dependencies = [
"chrono",
"colored",
"reqwest",
"scraper",
]
[[package]] [[package]]
name = "nodrop" name = "nodrop"
version = "0.1.14" version = "0.1.14"
@@ -1075,16 +1085,6 @@ dependencies = [
"winreg", "winreg",
] ]
[[package]]
name = "rust-tldr-news"
version = "0.1.0"
dependencies = [
"chrono",
"colored",
"reqwest",
"scraper",
]
[[package]] [[package]]
name = "rustc_version" name = "rustc_version"
version = "0.4.0" version = "0.4.0"
+1 -1
View File
@@ -1,5 +1,5 @@
[package] [package]
name = "rust-tldr-news" name = "news"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
+7 -1
View File
@@ -19,4 +19,10 @@ curl ... | sh
# Usage # Usage
Show me todays news: `rust-tldr today` ```
$ news today
```
```
$ news help
```
+14 -10
View File
@@ -31,6 +31,20 @@ fn main() {
println!("args: {:?}", args); println!("args: {:?}", args);
if args.len() == 1 { if args.len() == 1 {
print_help();
return;
}
let command = &args.get(1).unwrap();
match command.as_str() {
"today" => get_and_display_today_news(),
"help" => print_help(),
_ => println!("unknown command. use `news help` to see available commands"),
}
}
fn print_help() {
println!("About"); println!("About");
println!(" news is a cli tool to get the latest tech news from tldr.tech"); println!(" news is a cli tool to get the latest tech news from tldr.tech");
@@ -39,15 +53,6 @@ fn main() {
println!("{}", " $ news today".green()); println!("{}", " $ news today".green());
println!("{}", " $ news yesterday(not implemented)".blue()); println!("{}", " $ news yesterday(not implemented)".blue());
println!("{}", " $ news help".red()); println!("{}", " $ news help".red());
return;
}
let command = &args.get(1).unwrap();
match command.as_str() {
"today" => get_and_display_today_news(),
_ => println!("unknown command. use `news help` to see available commands"),
}
} }
fn get_and_display_today_news() { fn get_and_display_today_news() {
@@ -83,4 +88,3 @@ fn get_and_display_today_news() {
println!("\n"); println!("\n");
} }
} }