Skip to content

Runtime control of hidden options #736

@akoscz

Description

@akoscz

Is there a way to control the hidden attribute of a command line option at runtime? The use case I'm working with requires that an option should only be available to the user when executing the application on a specific operating system. For example:

private static final boolean isDarwin = Utils.isOSType(OSType.Darwin);

@CommandLine.Option(names = {"-o", "--open"}, 
    description = "On OSX open the finder to the data dir that was downloaded.", 
    showDefaultValue = CommandLine.Help.Visibility.ALWAYS, 
    hidden = !isDarwin) // hide this option on all OS's other than Darwin (OSX)
boolean open = false;

The above example would be ideal, although the compiler complains that the value for the hidden attribute must be a constant expression. I'm guessing it has to do with the way the annotation processor generates the code at compile time.

Since the above isn't supported, can I get at the CommandLine.Option object and toggle the hidden attribute at runtime, let's say like in the constructor of my object?

Any feedback is welcome. Thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions