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

Add differentiation of required opts in usage() #49

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
22 changes: 18 additions & 4 deletions gumdrop_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1811,11 +1811,25 @@ fn make_usage(help: &Option<String>, free: &[FreeOpt], opts: &[Opt]) -> String {
res.push('\n');
}

res.push_str("Optional arguments:\n");
let (required,optional): (Vec<&Opt>,Vec<&Opt>) =
opts.iter().partition(|o| o.required);

for opt in opts {
res.push_str(&opt.usage(width));
res.push('\n');
if !required.is_empty() {
res.push_str("Required arguments:\n");

for opt in required {
res.push_str(&opt.usage(width));
res.push('\n');
}
}

if !optional.is_empty() {
res.push_str("Optional arguments:\n");

for opt in optional {
res.push_str(&opt.usage(width));
res.push('\n');
}
}
}

Expand Down