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

Improve synopsis for commands with ArgGroups with positional parameters #1061

Closed
deining opened this issue May 20, 2020 · 4 comments
Closed
Labels
theme: arg-group An issue or change related to argument groups theme: usagehelp An issue or change related to the usage help message
Milestone

Comments

@deining
Copy link
Contributor

deining commented May 20, 2020

Derived from #1050:

import java.util.List;
import picocli.CommandLine;
import picocli.CommandLine.*;

@Command(name = "grades", mixinStandardHelpOptions = true)
public class App implements Runnable {

    static class StudentGrade {
        @Parameters(index = "0") String name;
        @Parameters(index = "1") int grade;
    }

     @ArgGroup(exclusive = false, multiplicity = "1..*")
    List<StudentGrade> gradeList;

    @Override
    public void run() {
    }

    public static void main(String[] args) {
        System.exit(new CommandLine(new App()).execute("-h"));
    }
}

This results in:

Usage: grades (<name> <grade>)... [-hV]
      <name>
      <grade>
  -h, --help      Show this help message and exit.
  -V, --version   Print version information and exit.

IMHO, it were appropriate to swap parameters and help + version options:

Usage: grades [-hV] (<name> <grade>)... 
@remkop remkop added theme: arg-group An issue or change related to argument groups theme: usagehelp An issue or change related to the usage help message labels May 21, 2020
@remkop remkop added this to the 4.4 milestone May 24, 2020
@remkop
Copy link
Owner

remkop commented Jun 2, 2020

One way to accomplish this is to make non-group options always precede argument groups in the synopsis. (Simple, predictable, but potentially some disruption for existing applications.)

Another idea is to only let options precede groups if the groups contain only positional parameters. Not sure if I like that idea. (Less predictable)

Yet another idea is to make this configurable. That would raise more questions: what API do we want to offer, and what is the scope? For example, making the synopsis for groups configurable will be complex.

Finally, we can leave it the way it is. (Simple, predictable, no disruption for existing applications, but sometimes gives a counter-intuitive synopsis.)

Thoughts?

@deining
Copy link
Contributor Author

deining commented Jun 2, 2020

One way to accomplish this is to make non-group options always precede argument groups in the synopsis. (Simple, predictable, but potentially some disruption for existing applications.)

IMHO, this is the way to go.

Yet another idea is to make this configurable.

That seems to be overkill for me.

Finally, we can leave it the way it is.

I'm not really happy with the current (inconsistent) way the synposis printed. That's why I raised and authored this issue.

Just my two cents.

@remkop
Copy link
Owner

remkop commented Jun 2, 2020

One way to accomplish this is to make non-group options always precede argument groups in the synopsis. (Simple, predictable, but potentially some disruption for existing applications.)

IMHO, this is the way to go.

I was thinking the same thing. We will do it that way.
Thanks for the feedback!

@remkop
Copy link
Owner

remkop commented Jun 4, 2020

One small complication is when the end-of-options [--] delimiter is to be shown in the synopsis.
For groups that have a mixture of options and positional parameters, we have little choice but to show this after the groups. But for groups with only positional parameters it is nice if we can display this between the options and the groups, so we get:

Usage: <main class> [-hV] [--] [<param00> | <param01>]

@remkop remkop closed this as completed in b712a97 Jun 4, 2020
remkop added a commit that referenced this issue Jun 6, 2020
…specify which options to show in the synopsis.

[#1061] API: Add method `Help::makeSynopsisFromParts` for building complex synopsis strings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: arg-group An issue or change related to argument groups theme: usagehelp An issue or change related to the usage help message
Projects
None yet
Development

No branches or pull requests

2 participants