firecracker
firecracker copied to clipboard
Jailer: added the `-h` flag as a shorthand for `--help`
Changes
Jailer: added the -h flag as a shorthand for --help.
Reason
This is a common convention - thought it would be useful.
License Acceptance
By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 license. For more information on following Developer
Certificate of Origin and signing off your commits, please check
CONTRIBUTING.md.
PR Checklist
- [ ] If a specific issue led to this PR, this PR closes the issue.
- [x] The description of changes is clear and encompassing.
- [ ] Any required documentation changes (code and docs) are included in this PR.
- [ ] API changes follow the Runbook for Firecracker API changes.
- [ ] User-facing changes are mentioned in
CHANGELOG.md. - [ ] All added/changed functionality is tested.
- [ ] New
TODOs link to an issue. - [x] Commits meet contribution quality standards.
- [x] This functionality cannot be added in
rust-vmm.
Additional Details
Tried to replicate the workings of the ArgParser by starting from https://github.com/firecracker-microvm/firecracker/blob/e67b2bedbe01a958cc3140f0e951bd5ffa98ff0a/src/jailer/src/main.rs#L318-L320
Which leads to https://github.com/firecracker-microvm/firecracker/blob/e67b2bedbe01a958cc3140f0e951bd5ffa98ff0a/src/utils/src/arg_parser.rs#L320-L323
From there I tried to replicate the logic with this small script to see if this patch would work:
use std::env;
const ARG_SEPARATOR: &str = "--";
const HELP_ARG: &str = "--help";
const SHORT_HELP_ARG: &str = "-h";
fn split_args(args: &[String]) -> (&[String], &[String]) {
if let Some(index) = args.iter().position(|arg| arg == ARG_SEPARATOR) {
return (&args[..index], &args[index + 1..]);
}
(args, &[])
}
fn parse(args: &[String]) {
// Skipping the first element of `args` as it is the name of the binary.
let (args, _) = split_args(&args[1..]);
if args.contains(&HELP_ARG.to_string()) || args.contains(&SHORT_HELP_ARG.to_string()) {
println!("found help args: {args:?}");
}
}
fn main() {
let args: Vec<String> = env::args().collect();
parse(&args)
}
I tried it out and saw the following:
➜ ~/src/temp/args_help git:(master) ✗ ./target/debug/args_help --help
found help args: ["--help"]
➜ ~/src/temp/args_help git:(master) ✗ ./target/debug/args_help -h
found help args: ["-h"]
➜ ~/src/temp/args_help git:(master) ✗ ./target/debug/args_help --helpo
➜ ~/src/temp/args_help git:(master) ✗ ./target/debug/args_help --h
➜ ~/src/temp/args_help git:(master) ✗ ./target/debug/args_help -hello
So it seems like this "should" work.