Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
remkop committed Aug 21, 2022
2 parents dac0ef7 + 1d369d2 commit 4870381
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package picocli.groovy

import org.junit.AfterClass
import org.junit.BeforeClass
import org.junit.Ignore
import org.junit.Test
import picocli.CommandLine
import picocli.CommandLine.InitializationException

@Ignore
class ClosureInAnnotationsDisabledTest {
@BeforeClass
public static void beforeClass() {
Expand Down
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);

}
}
37 changes: 37 additions & 0 deletions src/test/java/picocli/Issue1774.java
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"));
}
}

0 comments on commit 4870381

Please sign in to comment.