Skip to content

Commit

Permalink
[#1772] add test
Browse files Browse the repository at this point in the history
  • Loading branch information
remkop committed Aug 21, 2022
1 parent 6adfb87 commit 110416f
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/test/java/picocli/Issue1772.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package picocli;

import org.junit.Test;
import picocli.CommandLine;
import picocli.CommandLine.*;

import static org.junit.Assert.*;
import static picocli.CommandLine.ScopeType.INHERIT;

/**
* https://github.com/remkop/picocli/issues/1772
*/
public class Issue1772 {
public CommandLine getTestCommandLine(ParentTestCommand parentCommand, TestCommand testCommand, IFactory factory) {
CommandLine commandLine = new CommandLine(parentCommand, factory);
commandLine.addSubcommand(testCommand);
return commandLine;
}
@Command(name = "parentTestCommand", mixinStandardHelpOptions = true, scope = INHERIT)
static class ParentTestCommand {
}

@Command(name = "test")
static class TestCommand {
@Option(names = "-r")
public boolean option1;

public static String testString;

@Command(name = "subcommand")
void start(@Option(names = "-s") boolean option2) {
testString = "------> -r is " + option1 + " and -s is " + option2 + " <------";
}
}

@Test
public void testIssue1772() {
CommandLine commandLine = getTestCommandLine(new ParentTestCommand(), new TestCommand(), CommandLine.defaultFactory());
commandLine.execute("test", "-r", "subcommand", "-s");
assertEquals("------> -r is true and -s is true <------", TestCommand.testString);

}
}

0 comments on commit 110416f

Please sign in to comment.