|
5 | 5 | use clap::error::ErrorKind; |
6 | 6 | use clap::{arg, crate_version, value_parser, ArgMatches, Command}; |
7 | 7 |
|
8 | | -use crate::known_boards::KnownBoardNames; |
| 8 | +use crate::known_boards::list_known_board_names; |
9 | 9 |
|
10 | 10 | /// Create the [command](clap::Command) object which will handle all of the command line arguments. |
11 | 11 | pub fn make_cli() -> Command { |
@@ -65,11 +65,17 @@ fn get_channel_args() -> Vec<clap::Arg> { |
65 | 65 | let probe_args_ids = get_probe_args_ids().into_iter(); |
66 | 66 | let serial_args_ids = get_serial_args_ids().into_iter(); |
67 | 67 |
|
| 68 | + let known_board_names = list_known_board_names() |
| 69 | + .into_iter() |
| 70 | + .map(|x| x.to_str()) |
| 71 | + .collect::<Vec<_>>(); |
| 72 | + |
68 | 73 | vec![ |
69 | 74 | arg!(--serial "Use the serial bootloader to flash") |
70 | 75 | .action(clap::ArgAction::SetTrue) |
71 | 76 | .conflicts_with_all(probe_args_ids.clone().collect::<Vec<_>>()), |
72 | 77 | arg!(--board <BOARD> "Explicitly specify the board that is being targeted") |
| 78 | + .value_parser(known_board_names) |
73 | 79 | .conflicts_with_all( |
74 | 80 | serial_args_ids |
75 | 81 | .clone() |
@@ -130,23 +136,10 @@ pub fn validate(cmd: &mut Command, user_options: &ArgMatches) { |
130 | 136 | { |
131 | 137 | cmd.error( |
132 | 138 | ErrorKind::MissingRequiredArgument, |
133 | | - "the argument '--chip' is required for probe connections when not using a known board.", |
| 139 | + "the argument '--chip' is required for probe connections. This can be inferred using a known board ('--board').", |
134 | 140 | ) |
135 | 141 | .exit(); |
136 | 142 | } |
137 | | - |
138 | | - // Make sure 'board' is a known board |
139 | | - if let Some(board) = user_options.get_one::<String>("board") { |
140 | | - match KnownBoardNames::from_str(board) { |
141 | | - Some(_) => (), |
142 | | - None => cmd |
143 | | - .error( |
144 | | - ErrorKind::InvalidValue, |
145 | | - "the argument '--board' has an invalid value.", |
146 | | - ) |
147 | | - .exit(), |
148 | | - } |
149 | | - } |
150 | 143 | } |
151 | 144 |
|
152 | 145 | mod test { |
|
0 commit comments