Created
January 31, 2021 01:24
-
-
Save sualeh/22f425719d8409ca4cfdde2a341f50f3 to your computer and use it in GitHub Desktop.
Getting injected parse results
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
package schemacrawler.test.commandline.command; | |
import static org.junit.jupiter.api.Assertions.assertTrue; | |
import static org.junit.jupiter.api.Assertions.fail; | |
import org.junit.jupiter.api.Test; | |
import picocli.CommandLine; | |
import picocli.CommandLine.Command; | |
import picocli.CommandLine.Model.CommandSpec; | |
import picocli.CommandLine.Option; | |
import picocli.CommandLine.Spec; | |
public class FlatOptionsTest { | |
@Test | |
public void specCommandLine() throws Exception { | |
final String[] args = {"--option", "hello"}; | |
@Command(name = "base-command") | |
class SomeClass {} | |
@Command(name = "flatoptions") | |
class FlatOptions implements Runnable { | |
@Spec private CommandSpec spec; | |
@Option(names = "--option") | |
private String option; | |
@Override | |
public void run() { | |
assertTrue(option.equals("hello")); | |
if (spec.commandLine() == null) { | |
fail("Cannot get command-line or parse result here"); | |
} | |
} | |
} | |
final CommandSpec flatoptionsCommandSpec = CommandSpec.forAnnotatedObject(new FlatOptions()); | |
final CommandLine baseCommandLine = new CommandLine(new SomeClass()); | |
baseCommandLine.addMixin("flatoptions", flatoptionsCommandSpec); | |
baseCommandLine.parseArgs(args); | |
final Runnable runnable = (Runnable) baseCommandLine.getMixins().get("flatoptions"); | |
runnable.run(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment