IslandPenguin

main.rs

Mar 25th, 2021 (edited)
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.74 KB | None | 0 0
  1. use structopt::StructOpt;
  2. mod cli;
  3. mod task;
  4.  
  5.  
  6.  
  7. use cli::{Action::*, CommandLineArgs};
  8. use task::Task;
  9.  
  10. fn main() {
  11.  
  12.     // Get the command-line arguments.
  13.     let CommandLineArgs {
  14.         action,
  15.         todo_file,
  16.     } = CommandLineArgs::from_args();
  17.    
  18.     // Unpack the todo file.
  19.     let todo_file = todo_file.expect("Failed to find todo file");
  20.  
  21.     // Perform the action.
  22.     match action {
  23.         Add { text } => task::add_task(todo_file, Task::new(text)),
  24.         List => task::list_tasks(todo_file),
  25.         Done { position } => task::complete_task(todo_file, position),
  26.  
  27.     }
  28.     .expect("Failed to perform action")
  29.     println!("Press any key to continue");
  30.     stdin().read_line(&mut String::new()).unwrap();
  31. }
  32.  
Add Comment
Please, Sign In to add comment