Parse an single command line options and apply it to `config`.
(
opt: &str,
config: &mut dyn Configurable,
loc: Location,
)
| 105 | |
| 106 | /// Parse an single command line options and apply it to `config`. |
| 107 | pub fn parse_option( |
| 108 | opt: &str, |
| 109 | config: &mut dyn Configurable, |
| 110 | loc: Location, |
| 111 | ) -> Result<(), ParseOptionError> { |
| 112 | match TestOption::new(opt) { |
| 113 | TestOption::Flag(name) => match config.enable(name) { |
| 114 | Ok(_) => Ok(()), |
| 115 | Err(SetError::BadName(name)) => Err(ParseOptionError::UnknownFlag { loc, name }), |
| 116 | Err(_) => option_err!(loc, "not a boolean flag: '{}'", opt), |
| 117 | }, |
| 118 | TestOption::Value(name, value) => match config.set(name, value) { |
| 119 | Ok(_) => Ok(()), |
| 120 | Err(SetError::BadName(name)) => Err(ParseOptionError::UnknownValue { |
| 121 | loc, |
| 122 | name, |
| 123 | value: value.to_string(), |
| 124 | }), |
| 125 | Err(SetError::BadType) => option_err!(loc, "invalid setting type: '{}'", opt), |
| 126 | Err(SetError::BadValue(expected)) => { |
| 127 | option_err!( |
| 128 | loc, |
| 129 | "invalid setting value for '{}', expected {}", |
| 130 | opt, |
| 131 | expected |
| 132 | ) |
| 133 | } |
| 134 | }, |
| 135 | } |
| 136 | } |
no test coverage detected