making more usable with command usage

This commit is contained in:
talksik
2023-06-02 10:17:00 -07:00
parent b54ef81a21
commit fccd8cf4ae
2 changed files with 29 additions and 1 deletions
+4
View File
@@ -0,0 +1,4 @@
# bash script to clone the repo and display commands
# Clone the repo
git clone https://github.com/talksik/rust-tldr-news
+25 -1
View File
@@ -26,8 +26,31 @@ fn retrieve_local_file(file_name: &str) -> String {
} }
fn main() { fn main() {
println!("hello world"); // if no args, print commands
let args: Vec<String> = std::env::args().collect();
println!("args: {:?}", args);
if args.len() == 1 {
println!("About");
println!(" news is a cli tool to get the latest tech news from tldr.tech");
println!("Usage");
println!("{}", " $ news today".green());
println!("{}", " $ news yesterday(not implemented)".blue());
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() {
// format to 2023-06-05 // format to 2023-06-05
let today = Local::now(); let today = Local::now();
let formatted_date = today.format("%Y-%m-%d"); let formatted_date = today.format("%Y-%m-%d");
@@ -60,3 +83,4 @@ fn main() {
println!("\n"); println!("\n");
} }
} }