From ba89f114971ead4861b5b543f623fe879f982cb7 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 19 Nov 2023 17:21:21 +1300 Subject: [PATCH] Disallow strip-all with keep --- src/main.rs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/main.rs b/src/main.rs index d2072c85..3b71b6d1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -175,6 +175,9 @@ depth is changed, regardless of any options set.", .arg( Arg::new("keep") .help("Strip all metadata except in the comma-separated list") + .long_help("\ +Strip all metadata chunks except those in the comma-separated list. May be combined with \ +'--strip safe' to extend the list of chunks to be preserved.") .long("keep") .value_name("list"), ) @@ -622,12 +625,6 @@ fn parse_opts_into_struct( let names = strip .split(',') .map(|x| { - if x == "safe" || x == "all" { - return Err( - "'safe' or 'all' presets for --strip should be used by themselves" - .to_owned(), - ); - } let name = parse_chunk_name(x)?; if FORBIDDEN_CHUNKS.contains(&name) { return Err(format!("{} chunk is not allowed to be stripped", x)); @@ -642,16 +639,22 @@ fn parse_opts_into_struct( } if let Some(keep) = matches.get_one::("keep") { - if matches!(opts.strip, StripChunks::Strip(_)) { - return Err("--strip and --keep cannot be used together".to_owned()); - } let mut names: IndexSet<_> = keep .split(',') .map(parse_chunk_name) .collect::>()?; - if opts.strip == StripChunks::Safe { - // Add the keep safe chunks to the list - names.extend(StripChunks::KEEP_SAFE.iter().cloned()); + match opts.strip { + StripChunks::Strip(_) => { + return Err("The argument '--strip ' cannot be used with '--keep'".to_owned()); + } + StripChunks::All => { + return Err("The argument '--strip all' cannot be used with '--keep'".to_owned()); + } + StripChunks::Safe => { + // Add the keep safe chunks to the list + names.extend(StripChunks::KEEP_SAFE.iter().cloned()); + } + _ => {} } opts.strip = StripChunks::Keep(names); }