Fix --in-place option for hurlfmt

This commit is contained in:
Fabrice Reix 2023-05-30 15:43:59 +02:00 committed by jcamiel
parent 9d0a57b9fb
commit a3b6947eb7
No known key found for this signature in database
GPG Key ID: 07FF11CFD55356CC
3 changed files with 16 additions and 4 deletions

View File

@ -55,7 +55,7 @@ pub fn in_place() -> clap::Arg {
} }
pub fn input_file() -> clap::Arg { pub fn input_file() -> clap::Arg {
clap::Arg::new("INPUT") clap::Arg::new("input_file")
.help("Sets the input file to use") .help("Sets the input file to use")
.required(false) .required(false)
.index(1) .index(1)

View File

@ -83,7 +83,7 @@ pub fn in_place(arg_matches: &ArgMatches) -> Result<bool, OptionsError> {
} }
pub fn input_file(arg_matches: &ArgMatches) -> Result<Option<PathBuf>, OptionsError> { pub fn input_file(arg_matches: &ArgMatches) -> Result<Option<PathBuf>, OptionsError> {
match get_string(arg_matches, "INPUT") { match get_string(arg_matches, "input_file") {
None => Ok(None), None => Ok(None),
Some(s) => { Some(s) => {
let path = Path::new(&s); let path = Path::new(&s);

View File

@ -48,7 +48,6 @@ fn main() {
} }
}, },
}; };
init_colored(); init_colored();
let log_error_message = cli::make_logger_error_message(opts.color); let log_error_message = cli::make_logger_error_message(opts.color);
@ -128,7 +127,20 @@ fn main() {
} else { } else {
output output
}; };
write_output(output.into_bytes(), opts.output_file); let output_file = match opts.output_file {
None => {
if opts.in_place {
Some(
opts.input_file
.expect("an input file when --in-place is set"),
)
} else {
None
}
}
v => v,
};
write_output(output.into_bytes(), output_file);
} }
} }
} }