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

ArgGroup for help and generic options #1847

Open
rsenden opened this issue Oct 16, 2022 · 0 comments
Open

ArgGroup for help and generic options #1847

rsenden opened this issue Oct 16, 2022 · 0 comments

Comments

@rsenden
Copy link
Contributor

rsenden commented Oct 16, 2022

In the help output, we'd like to separate command-specific options from generic options like --help, --version, --log-level, ... At the same time, we'd also like to avoid having to define an ArgGroup in every individual command class to hold command-specific options; in many cases we can't even use ArgGroups because they cannot contain Mixins (#1793).

So, basically we'd like to put generic options in their own ArgGroup to remove them from the usage.optionListHeading section, such that we can exclusively use this section for command-specific options.

In our top-level command class, I now have the following code:

@Command(name = "fcli", 
    scope = ScopeType.INHERIT, 
    usageHelpAutoWidth = true,
    sortOptions = false, 
    showAtFileInUsageHelp = false,
    resourceBundle = "com.myapp.i18n.MyAppMessages",
    versionProvider = MyVersionProvider.class,
    subcommands = {
            SubCommand1.class,
            SubCommand2.class,
    }
)
public class MyAppCommands {
    @ArgGroup(exclusive = false, headingKey = "arggroup.loggingAndHelp.heading") 
    private LoggingAndHelpOptionsArgGroup loggingAndHelpOptionsArgGroup = new LoggingAndHelpOptionsArgGroup();
    
    private static final class LoggingAndHelpOptionsArgGroup {
        @Option(names = {"-V", "--version"}, versionHelp = true, description = "display version info", scope = ScopeType.INHERIT)
        boolean versionInfoRequested;

        @Option(names = {"-h", "--help"}, usageHelp = true, description = "display this help message", scope = ScopeType.INHERIT)
        boolean usageHelpRequested;
        
        @Option(names = "--log-level", scope = ScopeType.INHERIT)
        private String logLevel;
    }
}

Unfortunately, this doesn't achieve the desired result. On the top-level command, the logging and help options are correctly shown under arggroup.loggingAndHelp.heading, but the ArgGroup is not respected in subcommands (which is somewhat to be expected, as we're inheriting individual options rather than the ArgGroup); these options again appear under usage.optionListHeading.

Any chance we can have a scope = ScopeType.INHERIT attribute on ArgGroup, such that subcommands inherit the full ArgGroup rather than individual options?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant