Disallow strip-all with keep
This commit is contained in:
parent
97af04a539
commit
ba89f11497
1 changed files with 15 additions and 12 deletions
23
src/main.rs
23
src/main.rs
|
|
@ -175,6 +175,9 @@ depth is changed, regardless of any options set.",
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("keep")
|
Arg::new("keep")
|
||||||
.help("Strip all metadata except in the comma-separated list")
|
.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")
|
.long("keep")
|
||||||
.value_name("list"),
|
.value_name("list"),
|
||||||
)
|
)
|
||||||
|
|
@ -622,12 +625,6 @@ fn parse_opts_into_struct(
|
||||||
let names = strip
|
let names = strip
|
||||||
.split(',')
|
.split(',')
|
||||||
.map(|x| {
|
.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)?;
|
let name = parse_chunk_name(x)?;
|
||||||
if FORBIDDEN_CHUNKS.contains(&name) {
|
if FORBIDDEN_CHUNKS.contains(&name) {
|
||||||
return Err(format!("{} chunk is not allowed to be stripped", x));
|
return Err(format!("{} chunk is not allowed to be stripped", x));
|
||||||
|
|
@ -642,17 +639,23 @@ fn parse_opts_into_struct(
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(keep) = matches.get_one::<String>("keep") {
|
if let Some(keep) = matches.get_one::<String>("keep") {
|
||||||
if matches!(opts.strip, StripChunks::Strip(_)) {
|
|
||||||
return Err("--strip <list> and --keep cannot be used together".to_owned());
|
|
||||||
}
|
|
||||||
let mut names: IndexSet<_> = keep
|
let mut names: IndexSet<_> = keep
|
||||||
.split(',')
|
.split(',')
|
||||||
.map(parse_chunk_name)
|
.map(parse_chunk_name)
|
||||||
.collect::<Result<_, _>>()?;
|
.collect::<Result<_, _>>()?;
|
||||||
if opts.strip == StripChunks::Safe {
|
match opts.strip {
|
||||||
|
StripChunks::Strip(_) => {
|
||||||
|
return Err("The argument '--strip <list>' 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
|
// Add the keep safe chunks to the list
|
||||||
names.extend(StripChunks::KEEP_SAFE.iter().cloned());
|
names.extend(StripChunks::KEEP_SAFE.iter().cloned());
|
||||||
}
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
opts.strip = StripChunks::Keep(names);
|
opts.strip = StripChunks::Keep(names);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue