Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 13 additions & 2 deletions src/utils/src/arg_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub type Result<T> = result::Result<T, UtilsArgParserError>;
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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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::<Vec<String>>();

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)
Expand Down