Skip to content

Commit

Permalink
Update brioche-strip to error with invalid use of -o
Browse files Browse the repository at this point in the history
  • Loading branch information
kylewlacy committed Dec 22, 2024
1 parent 9f94473 commit 1fff57d
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions crates/brioche-strip/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,15 @@ enum RemapFile {
}

fn remap_files(args: &mut Vec<StripArg>, remapped_files: &mut Vec<RemapFile>) -> eyre::Result<()> {
let output_path_index = args.iter().enumerate().find_map(|(n, arg)| match arg {
let mut output_path_indices = args.iter().enumerate().filter_map(|(n, arg)| match arg {
StripArg::DashOPath(_) | StripArg::DashOFollowedByPath(_) => Some(n),
_ => None,
});
let output_path_index = output_path_indices.next();
eyre::ensure!(
output_path_indices.next().is_none(),
"-o argument specified multiple times"
);

if let Some(output_path_index) = output_path_index {
// Output path was specified. There should be one input path and
Expand All @@ -199,10 +204,16 @@ fn remap_files(args: &mut Vec<StripArg>, remapped_files: &mut Vec<RemapFile>) ->
};

// Get the input path
let input_path_index = args.iter().enumerate().find_map(|(n, arg)| match arg {
let mut input_path_indices = args.iter().enumerate().filter_map(|(n, arg)| match arg {
StripArg::InputPath(_) => Some(n),
_ => None,
});
let input_path_index = input_path_indices.next();
eyre::ensure!(
input_path_indices.next().is_none(),
"multiple input paths specified with -o"
);

let input_path_index = input_path_index.ok_or_eyre("input path not specified")?;
let input_path = match &args[input_path_index] {
StripArg::InputPath(path) => path.clone(),
Expand Down

0 comments on commit 1fff57d

Please sign in to comment.