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

Nested @ArgGroup adds @Options on outer level of command #722

Closed
srowatt opened this issue Jun 10, 2019 · 3 comments
Closed

Nested @ArgGroup adds @Options on outer level of command #722

srowatt opened this issue Jun 10, 2019 · 3 comments

Comments

@srowatt
Copy link

srowatt commented Jun 10, 2019

In the example code below I have created a command that has nested @ArgGroup options but there appears to be an issue where the options in the inner most arg group (i.e. --level-3a-param <level3aParam> and --level-3b-param <level3bParam>) are also being reported as available options in the outer level.

Usage: arg-group-test create (--level-1-param <level1Param> (--level-2a-param
                             <level2aParam>) (--level-2b-param <level2bParam>
                             (--level-3a-param <level3aParam>)
                             (--level-3b-param <level3bParam>)))
                             --level-0-param <level0Param> --level-3a-param
                             <level3aParam> --level-3b-param <level3bParam>
import lombok.Getter;
import picocli.CommandLine;
import picocli.CommandLine.ArgGroup;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;

public class ArgGroupTool {
	@Getter
	public static class Level1Argument {
		@Option(names = "--level-1-param", required = true)
		private String level1Param;
		@ArgGroup(exclusive = false, multiplicity = "1")
		private Level2aArgument level2a;
		@ArgGroup(exclusive = false, multiplicity = "1")
		private Level2bArgument level2b;
	}

	@Getter
	public static class Level2aArgument {
		@Option(names = "--level-2a-param", required = true)
		private String level2aParam;
	}

	@Getter
	public static class Level2bArgument {
		@Option(names = "--level-2b-param", required = true)
		private String level2bParam;
		@ArgGroup(exclusive = false, multiplicity = "1")
		private Level3aArgument level3a;
		@ArgGroup(exclusive = false, multiplicity = "1")
		private Level3bArgument level3b;
	}

	@Getter
	public static class Level3aArgument {
		@Option(names = "--level-3a-param", required = true)
		private String level3aParam;
	}

	@Getter
	public static class Level3bArgument {
		@Option(names = { "--level-3b-param"}, required = true)
		private String level3bParam;
	}

	@Command(name = "arg-group-test", separator = " ", subcommands = {CreateCommand.class, CommandLine.HelpCommand.class})
	public static class ArgGroupCommand implements Runnable {
		@Override
		public void run() {
		}
	}

	@Command(name = "create", separator = " ", helpCommand = true)
	public static class CreateCommand implements Runnable {
		@Option(names = "--level-0-param", required = true)
		private String level0Param;
		@ArgGroup(exclusive = false, multiplicity = "1")
		private Level1Argument level1;

		@Override
		public void run() {
		}
	}

	public static void main(final String[] args) {
		final CommandLine cmd = new CommandLine(new ArgGroupCommand());
		cmd.setExecutionStrategy(new CommandLine.RunAll());
		cmd.execute(args);

		if (args.length == 0) {
			cmd.usage(System.out, CommandLine.Help.Ansi.ON);
		}
	}
}
@remkop
Copy link
Owner

remkop commented Jun 10, 2019

Oh nice find! That looks like a bug. I will investigate...

@remkop remkop added this to the 4.0 milestone Jun 10, 2019
@remkop remkop closed this as completed in 2a0bd5c Jun 11, 2019
@remkop
Copy link
Owner

remkop commented Jun 11, 2019

Thanks for raising this. The logic for creating the synopsis for argument groups was incorrect and only worked for 2 levels of nesting. This is now fixed and should work for any level of nesting. Nice catch!

Fixed in master. Can you verify?

@remkop remkop modified the milestones: 4.0, 4.0-beta-2 Jun 18, 2019
@remkop
Copy link
Owner

remkop commented Jun 19, 2019

FYI, 4.0.0-beta-2 has been released. It may take a few hours for Maven mirrors to update.
Thanks again for the bug report!

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