Skip to content

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

@srowatt

Description

@srowatt

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);
		}
	}
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions