use of joptsimple.OptionSet in project PayFile by mikehearn.
the class CLI method main.
public static void main(String[] args) throws Exception {
BriefLogFormatter.init();
//Logger.getLogger("").setLevel(Level.OFF);
// allow client to choose another network for testing by passing through an argument.
OptionParser parser = new OptionParser();
parser.accepts("network").withRequiredArg().withValuesConvertedBy(regex("(mainnet)|(testnet)|(regtest)")).defaultsTo("mainnet");
parser.accepts("server").withRequiredArg().required();
parser.accepts("help").forHelp();
parser.formatHelpWith(new BuiltinHelpFormatter(120, 10));
OptionSet options;
try {
options = parser.parse(args);
} catch (OptionException e) {
System.err.println(e.getMessage());
System.err.println("");
parser.printHelpOn(System.err);
return;
}
if (options.has("help")) {
parser.printHelpOn(System.out);
return;
}
if (options.valueOf("network").equals(("testnet"))) {
params = TestNet3Params.get();
filePrefix = "testnet-";
} else if (options.valueOf("network").equals(("mainnet"))) {
params = MainNetParams.get();
filePrefix = "";
} else if (options.valueOf("network").equals(("regtest"))) {
params = RegTestParams.get();
filePrefix = "regtest-";
}
String server = options.valueOf("server").toString();
System.out.println("Connecting to " + server);
Socket socket = new Socket(server, 18754);
final CLI cli = new CLI(socket);
ShellFactory.createConsoleShell(server, "PayFile", cli).commandLoop();
cli.shutdown();
}
use of joptsimple.OptionSet in project spring-boot by spring-projects.
the class OptionHandler method run.
public final ExitStatus run(String... args) throws Exception {
String[] argsToUse = args.clone();
for (int i = 0; i < argsToUse.length; i++) {
if ("-cp".equals(argsToUse[i])) {
argsToUse[i] = "--cp";
}
}
OptionSet options = getParser().parse(argsToUse);
return run(options);
}
use of joptsimple.OptionSet in project spring-framework by spring-projects.
the class JOptCommandLinePropertySourceTests method withRequiredArg_andArgIsPresent.
@Test
public void withRequiredArg_andArgIsPresent() {
OptionParser parser = new OptionParser();
parser.accepts("foo").withRequiredArg();
OptionSet options = parser.parse("--foo=bar");
PropertySource<?> ps = new JOptCommandLinePropertySource(options);
assertThat((String) ps.getProperty("foo"), equalTo("bar"));
}
use of joptsimple.OptionSet in project spring-framework by spring-projects.
the class JOptCommandLinePropertySourceTests method withRequiredArg_andMultipleArgsPresent_usingRepeatedOption.
@Test
public void withRequiredArg_andMultipleArgsPresent_usingRepeatedOption() {
OptionParser parser = new OptionParser();
parser.accepts("foo").withRequiredArg().withValuesSeparatedBy(',');
OptionSet options = parser.parse("--foo=bar", "--foo=baz", "--foo=biz");
CommandLinePropertySource<?> ps = new JOptCommandLinePropertySource(options);
assertEquals(Arrays.asList("bar", "baz", "biz"), ps.getOptionValues("foo"));
assertThat(ps.getProperty("foo"), equalTo("bar,baz,biz"));
}
use of joptsimple.OptionSet in project spring-framework by spring-projects.
the class JOptCommandLinePropertySourceTests method withOptionalArg_andArgIsMissing.
@Test
public void withOptionalArg_andArgIsMissing() {
OptionParser parser = new OptionParser();
parser.accepts("foo").withOptionalArg();
OptionSet options = parser.parse("--foo");
PropertySource<?> ps = new JOptCommandLinePropertySource(options);
assertThat(ps.containsProperty("foo"), is(true));
assertThat((String) ps.getProperty("foo"), equalTo(""));
}
Aggregations