-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve --help
content in both firecracker and jailer
#1861
Improve --help
content in both firecracker and jailer
#1861
Conversation
src/utils/src/arg_parser.rs
Outdated
if is_required { | ||
arg.required | ||
} else { | ||
!arg.required | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if is_required { | |
arg.required | |
} else { | |
!arg.required | |
} | |
is_required == arg.required |
src/firecracker/src/main.rs
Outdated
@@ -106,11 +106,13 @@ fn main() { | |||
) | |||
.arg( | |||
Argument::new("start-time-us") | |||
.takes_value(true), | |||
.takes_value(true) | |||
.help("Wall clock time calculated by the jailer that it spent doing its work.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.help("Wall clock time calculated by the jailer that it spent doing its work.") | |
.help("Process start time (wall clock, microseconds).") |
src/firecracker/src/main.rs
Outdated
) | ||
.arg( | ||
Argument::new("start-time-cpu-us") | ||
.takes_value(true), | ||
.takes_value(true) | ||
.help("CPU time calculated by the jailer that it spent doing its work."), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.help("CPU time calculated by the jailer that it spent doing its work."), | |
.help("Process start CPU time (wall clock, microseconds)."), |
@aghecenco |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look really nice 👏.
The git history though is not accurate at this moment. You are fixing things from a previous commit in another one and the commit descriptions are not so clear anymore. Also, the changes are kind of mixed up.
I think the easy way out would be to squash the commits into a single one and enumerate in the commit message all the changes (except the ones that fix previous things or unit tests, fixing unit tests for a change that you introduce is implied and shouldn't be mentioned in a git message IMO). If you want to have separate commits, please keep them as clean as possible (for example, if you want a commit for the BTreeMap
change, that commit should contain only this change or if you want one for the unit testing part, it should contain only unit test changes).
src/utils/src/arg_parser.rs
Outdated
help_builder.concat() | ||
} | ||
|
||
fn arg_with_opt(&self) -> String { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rename this function, the arg
part should be already implied by the fact that this function belongs to Argument
, so we don't need to include it in the function name. Also, opt
seems a little bit ambiguous.
How about format_name()
?
src/utils/src/arg_parser.rs
Outdated
help_builder.concat() | ||
let optional_arguments = self.format_arguments(false); | ||
if !optional_arguments.is_empty() { | ||
// Add line break if `required_arguments` is pushed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
// Add line break if `required_arguments` is pushed | |
// Add line break if `required_arguments` is pushed. |
src/utils/src/arg_parser.rs
Outdated
.filter(|arg| is_required == arg.required) | ||
.collect::<Vec<_>>(); | ||
|
||
let arg_width = filtered_arguments |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we rename arg_width
to max_arg_width
to better suggest its purpose?
let mut help_builder = vec![]; | ||
|
||
help_builder.push(format!("--{}", self.name)); | ||
let arg = self.arg_with_opt(); | ||
help_builder.push(format!("{:<arg_width$}", arg, arg_width = arg_width)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
src/utils/src/arg_parser.rs
Outdated
} | ||
match (self.help, &self.default_value) { | ||
(Some(help), Some(default_value)) => { | ||
help_builder.push(format!(" {} (default {})", help, default_value)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
help_builder.push(format!(" {} (default {})", help, default_value)) | |
help_builder.push(format!("{} [default: {}]", help, default_value)) |
The three spaces from the beginning can be pushed before the match so you won't need to add them for every match
branch.
The default
formatting applies for the third match
branch too.
src/utils/src/arg_parser.rs
Outdated
|
||
assert_eq!(argument.format_help(), "--exec-file <exec-file>"); | ||
assert_eq!(argument.format_help(width), " --exec-file <exec-file>"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
width
parameter is somehow unrelated to the exact length of an argument (in this case the current argument), so I wouldn't test format_help()
with that length (which is updated for every arg in this test, so it's kind of a variable width).
I know you are checking at the end of this test the fixed width scenario too, but my suggestion would be to have two fixed widths defined at the beginning of the test (width
and other_width
or something like that) and for every argument to test format_help()
with those two widths.
It would be interesting to test format_help()
also with a smaller width than the minimum one that would be required for an argument to fit in (this check could be done I think for just an argument at the end of this test :-?).
What do you say?
1a0b890
to
ea3017a
Compare
@lauralt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, I have only two more nits.
Also, please update the coverage target value with the new one as it seems the test is failing now and shorten a little the commit title in order to follow the 50/72 rule (you can remove both
word for example).
src/utils/src/arg_parser.rs
Outdated
if self.takes_value { | ||
help_builder.push(format!(" <{}>", self.name)); | ||
} | ||
// Add three whitespaces between command and help message for readablity. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Add three whitespaces between command and help message for readablity. | |
// Add three whitespaces between the argument and its help message for readability. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/utils/src/arg_parser.rs
Outdated
@@ -150,20 +186,40 @@ impl<'a> Argument<'a> { | |||
self | |||
} | |||
|
|||
fn format_help(&self) -> String { | |||
fn format_help(&self, max_arg_width: usize) -> String { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, for this function context, I don't think max_arg_width
is an accurate name, it's more of a fixed width than max. I think I prefer the old version (arg_width
if I remember correctly).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thank you for the comment.
ea3017a
to
65930b0
Compare
@lauralt |
No.. that test is failing intermittently, we have an open issue for it: #1809 and a PR that is trying to fix it: #1898. So, another Anyway, it looks like you have a conflict in the coverage file. Meantime, there were merged some PRs which increased the coverage target pretty much, so the value added by you is not accurate anymore. |
65930b0
to
1bbf4c5
Compare
@lauralt |
Hi, @shioyama18! The coverage test is failing again :(. Can you please update the target value to |
Hi @lauralt, I added commit to update target value to |
Thanks, one more little thing :D: would be awesome if you could squash the commits into a single one, we don't usually have a separate commit just for the coverage change, sorry again :(. |
- Display default values along with the description - Segregate required and optional arguments - Sort and align arguments Signed-off-by: Shion Yamashita <shioyama1118@gmail.com>
30abe2c
to
fef9b11
Compare
No problem. Thank you for your kind review. |
Signed-off-by: Shion Yamashita shioyama1118@gmail.com
Reason for This PR
Fix: #1688
Description of Changes
Improve the following in
--help
contentrust-vmm
.License Acceptance
By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 license.
PR Checklist
[Author TODO: Meet these criteria.]
[Reviewer TODO: Verify that these criteria are met. Request changes if not]
git commit -s
).unsafe
code is properly documented.firecracker/swagger.yaml
.CHANGELOG.md
.