Skip to content
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

refactor: help rendering of multi-occurs/multi-values options #256

Merged
merged 1 commit into from
Oct 16, 2023
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
32 changes: 16 additions & 16 deletions src/param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,24 +211,24 @@ impl FlagOptionParam {
if self.is_flag() {
return String::new();
}
let output = self
.arg_value_names
.iter()
.map(|v| {
if self.multi_occurs() {
v.to_string()
} else {
format!("<{v}>")
}
})
.collect::<Vec<String>>()
.join(" ");

if self.multi_occurs() {
format!("[{output}]...")
let mut output = String::new();
if self.arg_value_names.len() == 1 {
let name: &String = &self.arg_value_names[0];
let value = match (self.required(), self.multi_occurs()) {
(true, true) => format!("<{name}>..."),
(false, true) => format!("[{name}]..."),
(_, false) => format!("<{name}>"),
};
output.push_str(&value);
} else {
output
let values = self
.arg_value_names
.iter()
.map(|v| format!("<{v}>"))
.collect::<Vec<String>>();
output.push_str(&values.join(" "));
}
output
}

pub(crate) fn render_describe(&self) -> String {
Expand Down
10 changes: 5 additions & 5 deletions tests/snapshots/integration__spec__option_help.snap
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ prog cmdb -h

OUTPUT
command cat >&2 <<-'EOF'
USAGE: prog cmdb --oa <OA> --ob [OB]... --oc [OC]... --oca <OCA> --ocb [OCB]... --occ [OCC]...
USAGE: prog cmdb --oa <OA> --ob <OB>... --oc <OC>... --oca <OCA> --ocb <OCB>... --occ <OCC>...

OPTIONS:
-a, --oa <OA>
--ob [OB]...
--oc [OC]...
--ob <OB>...
--oc <OC>...
--oca <OCA>
--ocb [OCB]...
--occ [OCC]...
--ocb <OCB>...
--occ <OCC>...
-h, --help

EOF
Expand Down
10 changes: 5 additions & 5 deletions tests/snapshots/integration__validate__option_missing.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ OUTPUT
command cat >&2 <<-'EOF'
error: the following required arguments were not provided:
--oa <OA>
--ob [OB]...
--oc [OC]...
--ob <OB>...
--oc <OC>...
--oca <OCA>
--ocb [OCB]...
--occ [OCC]...
--ocb <OCB>...
--occ <OCC>...

USAGE: prog cmdb --oa <OA> --ob [OB]... --oc [OC]... --oca <OCA> --ocb [OCB]... --occ [OCC]...
USAGE: prog cmdb --oa <OA> --ob <OB>... --oc <OC>... --oca <OCA> --ocb <OCB>... --occ <OCC>...

For more information, try '--help'.

Expand Down