Created
July 15, 2015 13:06
-
-
Save stalep/7840342051a1b03bd0f7 to your computer and use it in GitHub Desktop.
how to parse command line arguments
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
@CommandDefinition(name = "testparams", description = "") | |
public class TestParams implements Command { | |
@Option(shortName = 'f', description = "set the foo value") | |
private String foo; | |
@Option(shortName = 'b', required = true) | |
private String bar; | |
public static void main(String[] args) { | |
TestParams test = new TestParams(); | |
try { | |
ParserGenerator.parseAndPopulate(test, "testparams", args); | |
System.out.println("you set foo to: " + test.foo); | |
System.out.println("you set bar to: "+test.bar); | |
} | |
catch(CommandLineParserException e) { | |
System.out.println("Error when parsing: "+e.toString()); | |
} | |
catch(OptionValidatorException e) { | |
System.out.println("Validation failed: "+e.toString()); | |
} | |
} | |
@Override | |
//never called | |
public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException { | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment