| 164 | type Value = Memory; |
| 165 | |
| 166 | fn parse_ref( |
| 167 | &self, |
| 168 | cmd: &Command, |
| 169 | arg: Option<&Arg>, |
| 170 | value: &OsStr, |
| 171 | ) -> Result<Self::Value, clap::Error> { |
| 172 | let val = value |
| 173 | .to_str() |
| 174 | .ok_or_else(|| clap::Error::new(clap::error::ErrorKind::InvalidUtf8).with_cmd(cmd))?; |
| 175 | |
| 176 | Memory::from_str(val).map_err(|_| { |
| 177 | let mut err = clap::Error::new(clap::error::ErrorKind::ValueValidation).with_cmd(cmd); |
| 178 | |
| 179 | if let Some(arg) = arg { |
| 180 | err.insert( |
| 181 | ContextKind::InvalidArg, |
| 182 | ContextValue::String(arg.to_string()), |
| 183 | ); |
| 184 | } |
| 185 | |
| 186 | let context = ContextValue::String(val.to_string()); |
| 187 | err.insert(ContextKind::InvalidValue, context); |
| 188 | |
| 189 | err |
| 190 | }) |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | #[derive(Clone, Debug, Default, Display, EnumString, Eq, PartialEq, Serialize)] |