This commit is contained in:
Andrej Kolchin 2024-07-23 21:34:40 +03:00
parent 7a5365d7f4
commit 5af95c91af
2 changed files with 20 additions and 25 deletions

View File

@ -20,30 +20,24 @@ impl Base32Config {
pub fn base32_encoding(config: Base32Config) -> Result<Encoding, ShellError> { pub fn base32_encoding(config: Base32Config) -> Result<Encoding, ShellError> {
match (config.nopad, config.dnscurve, config.dnssec) { match (config.nopad, config.dnscurve, config.dnssec) {
(Some(nopad), Some(dnscurve), _) => { (Some(nopad), Some(dnscurve), _) => Err(ShellError::IncompatibleParameters {
return Err(ShellError::IncompatibleParameters { left_message: "Inapplicable to DNSCURVE".to_string(),
left_message: "Inapplicable to DNSCURVE".to_string(), left_span: nopad,
left_span: nopad, right_message: "Must be used standalone".to_string(),
right_message: "Must be used standalone".to_string(), right_span: dnscurve,
right_span: dnscurve, }),
}); (_, Some(dnscurve), Some(dnssec)) => Err(ShellError::IncompatibleParameters {
} left_message: "Incompatible with DNSCURVE".to_string(),
(_, Some(dnscurve), Some(dnssec)) => { left_span: dnssec,
return Err(ShellError::IncompatibleParameters { right_message: "Must be used standalone".to_string(),
left_message: "Incompatible with DNSCURVE".to_string(), right_span: dnscurve,
left_span: dnssec, }),
right_message: "Must be used standalone".to_string(), (Some(nopad), _, Some(dnssec)) => Err(ShellError::IncompatibleParameters {
right_span: dnscurve, left_message: "Inapplicable to DNSCURVE".to_string(),
}); left_span: nopad,
} right_message: "DNSCURVE must be used standalone".to_string(),
(Some(nopad), _, Some(dnssec)) => { right_span: dnssec,
return Err(ShellError::IncompatibleParameters { }),
left_message: "Inapplicable to DNSCURVE".to_string(),
left_span: nopad,
right_message: "DNSCURVE must be used standalone".to_string(),
right_span: dnssec,
});
}
(None, None, None) => Ok(data_encoding::BASE32), (None, None, None) => Ok(data_encoding::BASE32),
(Some(_), None, None) => Ok(data_encoding::BASE32_NOPAD), (Some(_), None, None) => Ok(data_encoding::BASE32_NOPAD),

View File

@ -99,7 +99,8 @@ impl Command for EncodeBase64 {
(Type::Binary, Type::String), (Type::Binary, Type::String),
]) ])
.allow_variants_without_examples(true) .allow_variants_without_examples(true)
.required("encoding", SyntaxShape::String, "encoding to use") .switch("url", "Use the URL-safe Base64 version.", None)
.switch("nopad", "Don't pad the output.", None)
.category(Category::Formats) .category(Category::Formats)
} }