Skip to content

Commit d6bbb22

Browse files
seafoodfryroypat
authored andcommitted
Jailer: added the -h flag as a shorthand for --help
This is a common convention. Signed-off-by: seafoodfry <[email protected]>
1 parent 18a2a05 commit d6bbb22

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ and this project adheres to
3232
[#4741](https://github.com/firecracker-microvm/firecracker/pull/4741),
3333
[#4746](https://github.com/firecracker-microvm/firecracker/pull/4746): Added
3434
official support for 6.1 microVM guest kernels.
35+
- [#4743](https://github.com/firecracker-microvm/firecracker/pull/4743): Added
36+
support for `-h` help flag to the Jailer. The Jailer will now print the help
37+
message with either `--help` or `-h`.
3538

3639
### Changed
3740

src/utils/src/arg_parser.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub type Result<T> = result::Result<T, UtilsArgParserError>;
99
const ARG_PREFIX: &str = "--";
1010
const ARG_SEPARATOR: &str = "--";
1111
const HELP_ARG: &str = "--help";
12+
const SHORT_HELP_ARG: &str = "-h";
1213
const VERSION_ARG: &str = "--version";
1314

1415
/// Errors associated with parsing and validating arguments.
@@ -330,10 +331,10 @@ impl<'a> Arguments<'a> {
330331
let (args, extra_args) = Arguments::split_args(&args[1..]);
331332
self.extra_args = extra_args.to_vec();
332333

333-
// If `--help` is provided as a parameter, we artificially skip the parsing of other
334+
// If `--help` or `-h`is provided as a parameter, we artificially skip the parsing of other
334335
// command line arguments by adding just the help argument to the parsed list and
335336
// returning.
336-
if args.contains(&HELP_ARG.to_string()) {
337+
if args.contains(&HELP_ARG.to_string()) || args.contains(&SHORT_HELP_ARG.to_string()) {
337338
let mut help_arg = Argument::new("help").help("Show the help message.");
338339
help_arg.user_value = Some(Value::Flag);
339340
self.insert_arg(help_arg);
@@ -652,6 +653,16 @@ mod tests {
652653

653654
arguments = arg_parser.arguments().clone();
654655

656+
let args = vec!["binary-name", "--exec-file", "foo", "-h"]
657+
.into_iter()
658+
.map(String::from)
659+
.collect::<Vec<String>>();
660+
661+
arguments.parse(&args).unwrap();
662+
assert!(arguments.args.contains_key("help"));
663+
664+
arguments = arg_parser.arguments().clone();
665+
655666
let args = vec!["binary-name", "--exec-file", "foo", "--version"]
656667
.into_iter()
657668
.map(String::from)

0 commit comments

Comments
 (0)