| 82 | type Value = SensitiveUrl; |
| 83 | |
| 84 | fn parse_ref( |
| 85 | &self, |
| 86 | cmd: &clap::Command, |
| 87 | arg: Option<&clap::Arg>, |
| 88 | value: &std::ffi::OsStr, |
| 89 | ) -> Result<Self::Value, clap::Error> { |
| 90 | let s = value |
| 91 | .to_str() |
| 92 | .ok_or_else(|| clap::Error::new(clap::error::ErrorKind::InvalidUtf8).with_cmd(cmd))?; |
| 93 | let url = s.parse().map_err(|_e| { |
| 94 | let mut err = clap::Error::new(clap::error::ErrorKind::ValueValidation); |
| 95 | if let Some(arg) = arg { |
| 96 | err.insert( |
| 97 | clap::error::ContextKind::InvalidArg, |
| 98 | clap::error::ContextValue::String(arg.to_string()), |
| 99 | ); |
| 100 | } |
| 101 | err.insert( |
| 102 | clap::error::ContextKind::InvalidValue, |
| 103 | clap::error::ContextValue::String("<redacted>".to_string()), |
| 104 | ); |
| 105 | // TODO: waiting on https://github.com/clap-rs/clap/issues/5065 |
| 106 | // to be resolved |
| 107 | // err.set_source(e); |
| 108 | err |
| 109 | })?; |
| 110 | Ok(SensitiveUrl(url)) |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | #[cfg(feature = "cli")] |