-
Notifications
You must be signed in to change notification settings - Fork 418
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
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/1774 | ||
*/ | ||
public class Issue1774 { | ||
public CommandLine getTestCommandLine(ParentTestCommand parentCommand, TestCommand testCommand, CommandLine.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 { | ||
@Command(name = "subcommand") | ||
void start(@Option(names = "-r", arity = "0") boolean optionR, | ||
@Option(names = "-s", arity = "0") boolean optionS, | ||
@Parameters(arity = "1") String url) { | ||
System.out.printf("optionR=%s, optionS=%s, url=%s%n", optionR, optionS, url); | ||
} | ||
} | ||
@Test | ||
public void testIssue1774() { | ||
CommandLine commandLine = getTestCommandLine(new ParentTestCommand(), new TestCommand(), CommandLine.defaultFactory()); | ||
assertEquals(0, commandLine.execute("test", "subcommand", "-r", "-s", "URL")); | ||
} | ||
} |