(commands: &[Node<'static>])
| 48 | } |
| 49 | |
| 50 | fn exec(commands: &[Node<'static>]) { |
| 51 | let mut index = 0; |
| 52 | while index < commands.len() { |
| 53 | let cmd = &commands[index]; |
| 54 | println!("> {} [{}]", cmd.question, cmd.default); |
| 55 | |
| 56 | let mut user_input = String::new(); |
| 57 | stdin().read_line(&mut user_input).unwrap(); |
| 58 | |
| 59 | let inp = user_input.trim(); |
| 60 | let result: Result<Action, &'static str>; |
| 61 | if !inp.is_empty() { |
| 62 | result = (cmd.callback)(inp); |
| 63 | } else { |
| 64 | result = (cmd.callback)(cmd.default); |
| 65 | } |
| 66 | |
| 67 | match result { |
| 68 | Ok(action) => match action { |
| 69 | Action::Retry => continue, |
| 70 | Action::Next => index += 1, |
| 71 | Action::Quit => break, |
| 72 | }, |
| 73 | Err(why) => panic!("{:?}", why), |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | fn make_project(s: &str) -> Result<Action, &'static str> { |
| 79 | if Path::new(s).exists() { |
no test coverage detected