本文整理汇总了Java中com.beust.jcommander.JCommander.parse方法的典型用法代码示例。如果您正苦于以下问题:Java JCommander.parse方法的具体用法?Java JCommander.parse怎么用?Java JCommander.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.beust.jcommander.JCommander
的用法示例。
在下文中一共展示了JCommander.parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processCommandLineArguments
import com.beust.jcommander.JCommander; //导入方法依赖的package包/类
/**
* Use JCommander to process the provided command-line arguments.
* This method is an instance method (not static) to allow JCommander
* to use this instance's JCommander-annotated fields.
*
* @param arguments Command-line arguments.
*/
private void processCommandLineArguments(final String[] arguments)
{
final JCommander commander
= JCommander.newBuilder()
.programName("JCommander Demonstration")
.addObject(this)
.verbose(1)
.build();
commander.parse(arguments);
if (help)
{
commander.usage();
}
else
{
out.println("The file name provided is '" + file + "' and verbosity is set to " + verbose);
}
}
示例2: parse
import com.beust.jcommander.JCommander; //导入方法依赖的package包/类
/**
* Parses command line arguments and populates this command line instance.
* <p>
* If the command line arguments include the "help" argument, or if the
* arguments have incorrect values or order, then usage information is
* printed to {@link System#out} and the program terminates.
*
* @param args
* the command line arguments
* @return an instance of the parsed arguments object
*/
public Arguments parse(String[] args) {
JCommander jCommander = new JCommander(this);
jCommander.setProgramName("jsonschema2pojo");
try {
jCommander.parse(args);
if (this.showHelp) {
jCommander.usage();
exit(EXIT_OKAY);
}
} catch (ParameterException e) {
System.err.println(e.getMessage());
jCommander.usage();
exit(EXIT_ERROR);
}
return this;
}
示例3: main
import com.beust.jcommander.JCommander; //导入方法依赖的package包/类
public static void main(String[] args) {
Injector injector = Guice.createInjector(new MavenModule(), new MavenCommandOptionsModule(), new XmlModule());
OptionalArgs optionalArgs = injector.getInstance(OptionalArgs.class);
JCommander jCommander = JCommander.newBuilder().addObject(optionalArgs).build();
jCommander.setProgramName("mvnUploader");
jCommander.parse(args);
if (optionalArgs.isHelp()){
jCommander.usage();
} else {
logger.info("Welcome To Maven Artifacts Uploader");
Uploader uploader = injector.getInstance(Uploader.class);
uploader.uploadToRepository(Paths.get(optionalArgs.getPathToArtifacts()));
logger.info("Done uploading all the artifacts!");
}
}
示例4: VerbSenseArgumentCounter
import com.beust.jcommander.JCommander; //导入方法依赖的package包/类
private VerbSenseArgumentCounter(String... args) {
JCommander cmd = new JCommander(this);
cmd.setProgramName(this.getClass().getSimpleName());
try {
if (args.length == 0) {
cmd.usage();
System.exit(0);
}
cmd.parse(args);
} catch (ParameterException e) {
System.err.println(e.getMessage());
cmd.usage();
System.exit(1);
}
initializeDb();
initializeAnnotator();
validateDir();
}
示例5: parse
import com.beust.jcommander.JCommander; //导入方法依赖的package包/类
public static Options parse(String[] cliArgs) {
Options args = new Options();
JCommander jc = JCommander.newBuilder()
.addObject(args)
.build();
jc.parse(cliArgs);
if(args.help){
jc.setProgramName("dremio-admin clean");
jc.usage();
}
return args;
}
示例6: main
import com.beust.jcommander.JCommander; //导入方法依赖的package包/类
@SuppressWarnings("checkstyle:Regexp")
public static void main(final String[] args) throws IOException
{
final CommandLineArgs commandLineArgs = new CommandLineArgs();
final JCommander jCommander = new JCommander(commandLineArgs);
try
{
jCommander.parse(args);
}
catch (final ParameterException p)
{
printUsage(p.getJCommander());
System.exit(1);
}
if (commandLineArgs.isHelp())
{
jCommander.usage();
return;
}
final String gitHash = commandLineArgs.getGitHash();
if (gitHash == null || gitHash.isEmpty())
{
System.err.println("-g (GitHash) null or empty");
printUsage(jCommander);
System.exit(2);
}
final InfluxJmhReportPublisher influxJmhReportPublisher = new InfluxJmhReportPublisher();
final InfluxJmhReporter influxJmhReporter = new InfluxJmhReporter(influxJmhReportPublisher, new FileReader(),
commandLineArgs.getInfluxUrl(),
commandLineArgs.getGitHash(),
commandLineArgs.getHostname());
final List<String> jsonFiles = commandLineArgs.getJsonFiles();
influxJmhReporter.reportResult(jsonFiles);
}
示例7: LuceneIndexReader
import com.beust.jcommander.JCommander; //导入方法依赖的package包/类
private LuceneIndexReader(String... args) {
JCommander cmd = new JCommander(this);
cmd.setProgramName(this.getClass().getSimpleName());
try {
cmd.parse(args);
} catch (ParameterException e) {
System.err.println(e.getMessage());
cmd.usage();
System.exit(1);
}
}
示例8: spaceSeparator
import com.beust.jcommander.JCommander; //导入方法依赖的package包/类
@Test
public void spaceSeparator() throws Exception {
GenerateWorkspaceOptions options = new GenerateWorkspaceOptions();
JCommander optionParser = JCommander.newBuilder().addObject(options).build();
optionParser.parse("--artifact", "foo:bar:1.2.3");
assertThat(options.artifacts).contains("foo:bar:1.2.3");
}
示例9: noCommaDelimiter
import com.beust.jcommander.JCommander; //导入方法依赖的package包/类
@Test
public void noCommaDelimiter() throws Exception {
GenerateWorkspaceOptions options = new GenerateWorkspaceOptions();
JCommander optionParser = JCommander.newBuilder().addObject(options).build();
optionParser.parse("--artifact", "foo:bar:[1.2.3,)");
assertThat(options.artifacts).contains("foo:bar:[1.2.3,)");
}
示例10: parse
import com.beust.jcommander.JCommander; //导入方法依赖的package包/类
public static BackupManagerOptions parse(String[] cliArgs) {
BackupManagerOptions args = new BackupManagerOptions();
JCommander jc = JCommander.newBuilder()
.addObject(args)
.build();
jc.parse(cliArgs);
if(args.help){
jc.usage();
System.exit(0);
}
return args;
}
示例11: main
import com.beust.jcommander.JCommander; //导入方法依赖的package包/类
public static void main(final String[] args) throws Exception {
final Map<String, IWalleCommand> subCommandList = new HashMap<String, IWalleCommand>();
subCommandList.put("show", new ShowCommand());
subCommandList.put("rm", new RemoveCommand());
subCommandList.put("put", new PutCommand());
subCommandList.put("batch", new BatchCommand());
subCommandList.put("batch2", new Batch2Command());
final WalleCommandLine walleCommandLine = new WalleCommandLine();
final JCommander commander = new JCommander(walleCommandLine);
for (Map.Entry<String, IWalleCommand> commandEntry : subCommandList.entrySet()) {
commander.addCommand(commandEntry.getKey(), commandEntry.getValue());
}
try {
commander.parse(args);
} catch (ParameterException e) {
System.out.println(e.getMessage());
commander.usage();
System.exit(1);
return;
}
walleCommandLine.parse(commander);
final String parseCommand = commander.getParsedCommand();
if (parseCommand != null) {
subCommandList.get(parseCommand).parse();
}
}
示例12: EmbeddingBinarizer
import com.beust.jcommander.JCommander; //导入方法依赖的package包/类
private EmbeddingBinarizer(String... args) {
JCommander cmd = new JCommander(this);
cmd.setProgramName(this.getClass().getSimpleName());
try {
cmd.parse(args);
} catch (ParameterException e) {
System.out.println(e.getMessage());
cmd.usage();
System.exit(1);
}
}
示例13: KMeansCalculator
import com.beust.jcommander.JCommander; //导入方法依赖的package包/类
private KMeansCalculator(String... args) {
JCommander cmd = new JCommander(this);
cmd.setProgramName(this.getClass().getSimpleName());
try {
cmd.parse(args);
} catch (ParameterException e) {
System.out.println(e.getMessage());
cmd.usage();
System.exit(1);
}
}
示例14: main
import com.beust.jcommander.JCommander; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException, InterruptedException {
SenseHatTester senseHatTester = new SenseHatTester();
Map<String, Command> commands = new HashMap<>();
commands.put("fill", new FillCommand());
commands.put("set-pixel", new SetPixelCommand());
commands.put("save-image", new SaveImageCommand());
commands.put("load-image", new LoadImageCommand());
commands.put("env", new EnvCommand());
commands.put("pulse", new PulseCommand());
commands.put("text", new TextCommand());
commands.put("clock", new BinaryClockCommand());
JCommander.Builder builder = JCommander.newBuilder()
.addObject(senseHatTester);
commands.forEach((name, cmd) -> builder.addCommand(name, cmd));
JCommander jCommander = builder.build();
jCommander.parse(args);
if(senseHatTester.isPrintUsage()) {
jCommander.usage();
return;
}
String parsedCommand = jCommander.getParsedCommand();
if (parsedCommand != null && commands.containsKey(parsedCommand)) {
SenseHat senseHat;
try {
if(senseHatTester.getFrameBuffer() != null) {
senseHat = new SenseHat(senseHatTester.getFrameBuffer());
} else {
senseHat = new SenseHat();
}
} catch (IllegalStateException e) {
log.error(e.getLocalizedMessage(), e);
return;
}
commands.get(parsedCommand).run(senseHat);
} else {
jCommander.usage();
}
}
示例15: main
import com.beust.jcommander.JCommander; //导入方法依赖的package包/类
public static void main(String... argv) throws Exception {
//Attempt to determine verbose level first
final Now now = new Now();
JCommander.newBuilder().addObject(now)
.acceptUnknownOptions(true)
.build().parse(argv);
final CommandMain commandMain = new CommandMain();
final JCommander.Builder commanderBuilder = JCommander.newBuilder()
.programName("java -jar now4j-cli-<version>.jar")
.verbose(now.verboseLevel)
.addObject(commandMain);
for (final Map.Entry<String, AbstractCommand> commandEntry : commandMap.entrySet()) {
commanderBuilder.addCommand(commandEntry.getKey(), commandEntry.getValue());
}
final JCommander commander = commanderBuilder.build();
commander.parse(argv);
if (commandMain.help) {
commander.usage();
return;
}
final NowClient nowClient;
final String token = commandMain.token;
if (token == null || token.isEmpty()) {
//Default Now Client, with no option => read from /.now.json file
nowClient = NowClient.create();
} else {
//There is a token option
final String team = commandMain.team;
if (team == null || team.isEmpty()) {
//Read team from /.now.json, if any
nowClient = NowClient.create(token);
} else {
nowClient = NowClient.create(token, team);
}
}
final String parsedCommand = commander.getParsedCommand();
if (!commandMap.containsKey(parsedCommand)) {
throw new IllegalArgumentException("Unsupported command: " +
parsedCommand + ". Possible commands: " + commandMap.keySet());
}
final AbstractCommand abstractCommand = commandMap.get(parsedCommand);
abstractCommand.setNowClient(nowClient);
abstractCommand.work();
}