diff --git a/CHANGELOG.md b/CHANGELOG.md index a1537bfb707..9a44cc10356 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,9 @@ and this project adheres to [#4741](https://github.com/firecracker-microvm/firecracker/pull/4741), [#4746](https://github.com/firecracker-microvm/firecracker/pull/4746): Added official support for 6.1 microVM guest kernels. +- [#4743](https://github.com/firecracker-microvm/firecracker/pull/4743): Added + support for `-h` help flag to the Jailer. The Jailer will now print the help + message with either `--help` or `-h`. ### Changed diff --git a/src/utils/src/arg_parser.rs b/src/utils/src/arg_parser.rs index efef4a27514..47dfe3a88a4 100644 --- a/src/utils/src/arg_parser.rs +++ b/src/utils/src/arg_parser.rs @@ -9,6 +9,7 @@ pub type Result = result::Result; const ARG_PREFIX: &str = "--"; const ARG_SEPARATOR: &str = "--"; const HELP_ARG: &str = "--help"; +const SHORT_HELP_ARG: &str = "-h"; const VERSION_ARG: &str = "--version"; /// Errors associated with parsing and validating arguments. @@ -330,10 +331,10 @@ impl<'a> Arguments<'a> { let (args, extra_args) = Arguments::split_args(&args[1..]); self.extra_args = extra_args.to_vec(); - // If `--help` is provided as a parameter, we artificially skip the parsing of other + // If `--help` or `-h`is provided as a parameter, we artificially skip the parsing of other // command line arguments by adding just the help argument to the parsed list and // returning. - if args.contains(&HELP_ARG.to_string()) { + if args.contains(&HELP_ARG.to_string()) || args.contains(&SHORT_HELP_ARG.to_string()) { let mut help_arg = Argument::new("help").help("Show the help message."); help_arg.user_value = Some(Value::Flag); self.insert_arg(help_arg); @@ -652,6 +653,16 @@ mod tests { arguments = arg_parser.arguments().clone(); + let args = vec!["binary-name", "--exec-file", "foo", "-h"] + .into_iter() + .map(String::from) + .collect::>(); + + arguments.parse(&args).unwrap(); + assert!(arguments.args.contains_key("help")); + + arguments = arg_parser.arguments().clone(); + let args = vec!["binary-name", "--exec-file", "foo", "--version"] .into_iter() .map(String::from)