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

Can required options be inherited? #1001

Closed
remkop opened this issue Apr 22, 2020 · 0 comments
Closed

Can required options be inherited? #1001

remkop opened this issue Apr 22, 2020 · 0 comments
Labels
theme: parser An issue or change related to the parser
Milestone

Comments

@remkop
Copy link
Owner

remkop commented Apr 22, 2020

Ticket #649 provided support for inherited options.
This is a follow-up ticket for the following scenario.

Problem

Suppose we define a command with a required = true option that is also marked as scope = INHERIT, and a subcommand, like this:

@Command
class App {
    @Option(names = "-x", required = true, scope = INHERIT)
    int x;
    
    @Command void sub() {}
}

Now, if the end user invokes the command with the following parameters:

<cmd> sub -x=2

Currently, validation on the required options of the top-level command is done when the parser detects that a subcommand was invoked. Since at that point the required option has not been matched yet, the parser gives this error: Missing required option '-x=<x>'.

Solutions

  1. One idea is to simply (in this release) prevent applications from combining required options from being INHERIT-ed. Picocli could throw an InitializationException at startup when it creates the model.
  2. Alternatively, investigate if it is possible (how big a change it is) to postpone the validation of required inherited options. If unmatched required args are not inherited we can fail immediately like we do now. The inherited required args can be passed on to the subcommand; this subcommand should then only verify inherited required args if they are "passed on" (because they have not been matched yet on the parent command). Again, non-inherited required args can be validated unconditionally.
@remkop remkop added the theme: parser An issue or change related to the parser label Apr 22, 2020
@remkop remkop added this to the 4.3 milestone Apr 22, 2020
remkop added a commit that referenced this issue May 1, 2020
@remkop remkop closed this as completed in 2602687 May 2, 2020
jerrylususu pushed a commit to jerrylususu/picocli that referenced this issue May 4, 2020
jerrylususu pushed a commit to jerrylususu/picocli that referenced this issue May 4, 2020
jerrylususu pushed a commit to jerrylususu/picocli that referenced this issue May 4, 2020
jerrylususu pushed a commit to jerrylususu/picocli that referenced this issue May 4, 2020
jerrylususu pushed a commit to jerrylususu/picocli that referenced this issue May 4, 2020
jerrylususu pushed a commit to jerrylususu/picocli that referenced this issue May 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: parser An issue or change related to the parser
Projects
None yet
Development

No branches or pull requests

1 participant