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

Parse Multiple Commands and their options from one line #319

Closed
bmaxwell opened this issue Apr 1, 2018 · 4 comments
Closed

Parse Multiple Commands and their options from one line #319

bmaxwell opened this issue Apr 1, 2018 · 4 comments
Labels

Comments

@bmaxwell
Copy link

bmaxwell commented Apr 1, 2018

In issue #127 , it looked like picocli could parse out multiple commands, but I am having issues.

It looks like it parses the top level Command and then 1 sub command, then it warns the 2nd command is unmatched, it appears it is looking at the 1st subcommand instead of the top level command to match. Is there something missing in the setup or is this currently not possible?

[picocli WARN] Unmatched arguments: [def, -d, dvalue]
picocli.CommandLine command: Config
picocli.CommandLine command: abc

Since there are no positional parameters, I was trying to get Config, abc, def all parsed.

@Command(name="Config", subcommands={ABC.class, DEF.class})
public static class Config {
	@Option(names={"-c"})
	private String c;	
	public String getC() {
		return c;
	}
}	
@Command(name="abc", subcommands={})
public static class ABC {
	@Option(names={"-a"})
	private String a;		
	public String getA() {
		return a;
	}
}	
@Command(name="def", subcommands={})
public static class DEF {
	@Option(names={"-d"})
	private String d;		
	public String getD() {
		return d;
	}
}
public static void main(String[] args) {
	String[] testArgs = {"-c", "cvalue", "abc", "-a", "avalue", "def", "-d", "dvalue" };
	Config cfg = new Config();
	CommandLine commandLine = new CommandLine(cfg);
	commandLine.setUnmatchedArgumentsAllowed(true);
	List<CommandLine> recognized = commandLine.parse(testArgs);
	for(CommandLine cl : recognized) {			
		System.out.printf("%s command: %s\n", cl.getClass().getName(), cl.getCommandName());
	}
}
@remkop
Copy link
Owner

remkop commented Apr 1, 2018

The issue you mentioned (#127) resulted in the current picocli behaviour: picocli expects the command line to contain a hierarchy of subcommands. So if it sees a command line like this:

config abc def

... picocli expects def to be a subcommand of abc.

I believe this is the convention used by most other command line apps.

That said, I would not oppose an acceptSiblingSubcommands parser mode being added. Are you interested in contributing a pull request for this?

@kaibioinfo
Copy link

I would like such an option, too. It would allow to use subcommands for grouping options.

@remkop
Copy link
Owner

remkop commented Mar 4, 2019

Hi @bmaxwell and @kaibioinfo, the plan is that picocli 4.0 will add support for composite repeating groups.

The goal is that argument groups will support:

This is currently work in progress, and an early (but insufficient - lacking support for repeating composite arguments) version is currently in master. The #199 ticket has some comments that describe the current state of things and follow-up plans.

@remkop remkop added this to the 4.0 milestone Mar 19, 2019
@remkop remkop added the status: duplicate 👨🏻‍🤝‍👨🏻 A duplicate of another issue label Jun 13, 2019
@remkop
Copy link
Owner

remkop commented Jun 13, 2019

Closing this ticket as a duplicate of #454.
#454 has more discussion of the use case.

@remkop remkop closed this as completed Jun 13, 2019
@remkop remkop removed this from the 4.0 milestone Jun 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants