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

Subcommands hidden from usage help shown as suggestions #887

Closed
deining opened this issue Nov 28, 2019 · 2 comments
Closed

Subcommands hidden from usage help shown as suggestions #887

deining opened this issue Nov 28, 2019 · 2 comments
Milestone

Comments

@deining
Copy link
Contributor

deining commented Nov 28, 2019

Minimal example

1  import picocli.CommandLine;
2  import picocli.CommandLine.Command;
3
4  @Command(name="Completion", subcommands = { picocli.AutoComplete.GenerateCompletion.class, CommandLine.HelpCommand.class } )
public class CompletionSubcommandDemo implements Runnable {
6
7      public static void main(String... args) {
8          CommandLine cmd = new CommandLine(new CompletionSubcommandDemo());
9          CommandLine gen = cmd.getSubcommands().get("generate-completion");
10          gen.getCommandSpec().usageMessage().hidden(true);
11          cmd.usage(System.out);
12          // cmd.execute("ge");
13      }
14
15      @Override
16      public void run() {
17      }
18  }

If I run this, I'm getting:

Usage: Completion [COMMAND]
Commands:
  help  Displays help information about the specified command

Subcommand generate-completion is ommited from the command list, as requested in code.

No, remove comment in line 12 and comment out line 11. Run again, this time you are getting as output:

Unmatched argument at index 0: 'ge'
Did you mean: generate-completion?

What puzzles me here:
If one wants to omit the subcommand from the usage help message, there is most likely a good reason for this. However, the suggestion for completion now exactly shows the subcommand that is supposed to be hidden from the usage help, which might be unwanted. IMHO, it were better here to exclude the generate-completion subcommand from the suggestions given. The same is true for tab completion that can be put in place for the command: here, once the user presses TAB after typing in the command name, the subcommand generate-completionis printed out as suggested command, too:

$ MyCommand
generate-completion   help

Bug or feature? What do you think?

@remkop remkop added this to the 4.1.2 milestone Nov 29, 2019
@remkop
Copy link
Owner

remkop commented Nov 29, 2019

It makes sense to exclude hidden subcommands from auto-completion or unmatched argument suggestions. Currently neither auto-completion nor the unmatched argument suggestions take hidden into account (for subcommands, but also for options and positional parameters)...

Perhaps it should be configurable, where the default is that hidden options/subcommands are not suggested, but applications who like the previous behaviour can get it if they want.

remkop added a commit that referenced this issue Dec 4, 2019
remkop added a commit that referenced this issue Dec 6, 2019
…tions in unmatched argument usage help or autocompletion scripts
@remkop
Copy link
Owner

remkop commented Dec 6, 2019

Fixed in master. (I did not make it configurable.)
Please verify if you have a chance.

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

No branches or pull requests

2 participants