arostech_cli_rust/models/
menu.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use inquire::Select;

use super::menu_options::MenuOptions;

pub struct Menu {
  options: MenuOptions,
  pub should_show_menu: bool
}

impl Menu { 
  pub fn new () -> Menu {
    Menu {
      options: MenuOptions::new(),
      should_show_menu: true
    }
  }
  pub fn show_menu(&mut self) {

    let response = Select::new("Choose an action:", self.options.clone())
    .prompt()
    ;

    match response {
        Ok(choice) => self.should_show_menu = self.options.run(choice),
        Err(_) => {
          println!("Something went wrong!");
          self.should_show_menu = false;
        }
    };
  }
}