diff --git a/src/main/java/overview.html b/src/main/java/overview.html index 77a69572a..0beb3995f 100644 --- a/src/main/java/overview.html +++ b/src/main/java/overview.html @@ -15,16 +15,16 @@
Picocli provides a number of convenience methods
that allow you to omit error handling and other boilerplate code for common use cases.
- Here is a small example application that uses the CommandLine.call
convenience method
+ Here is a small example application that uses the CommandLine.execute
convenience method
to do parsing and error handling in one line of code.
The full user manual is hosted at http://picocli.info.
-@Command(name = "checksum", mixinStandardHelpOptions = true, version = "Checksum 2.0", +@Command(name = "checksum", mixinStandardHelpOptions = true, version = "Checksum 4.0", description = "Prints the checksum (MD5 by default) of a file to STDOUT.") -class CheckSum implements Callable<Void> { +class CheckSum implements Callable<Integer> { @Parameters(index = "0", description = "The file whose checksum to calculate.") private File file; @@ -35,16 +35,17 @@ public static void main(String[] args) throws Exception { // CheckSum implements Callable, so parsing, error handling and handling user // requests for usage help or version help can be done with one line of code. - CommandLine.call(new CheckSum(), args); + int exitCode = new CommandLine(new CheckSum()).execute(args); + // System.exit(exitCode); } @Override - public Void call() throws Exception { + public Integer call() throws Exception { // your business logic goes here byte[] fileContents = Files.readAllBytes(file.toPath()); byte[] digest = MessageDigest.getInstance(algorithm).digest(fileContents); - System.out.println(javax.xml.bind.DatatypeConverter.printHexBinary(digest)); - return null; + System.out.printf("%0" + (digest.length*2) + "x%n", new BigInteger(1, digest)); + return 0; } }diff --git a/src/main/java/picocli/CommandLine.java b/src/main/java/picocli/CommandLine.java index 023d531c9..c01d2327e 100644 --- a/src/main/java/picocli/CommandLine.java +++ b/src/main/java/picocli/CommandLine.java @@ -101,12 +101,12 @@ * -vooutfile in1 in2 * *
- * Another example that implements {@code Callable} and uses the {@link #call(Callable, String...) CommandLine.call} convenience API to run in a single line of code: + * Another example that implements {@code Callable} and uses the {@link #execute(String...) CommandLine.execute} convenience API to run in a single line of code: *
** @Command(description = "Prints the checksum (MD5 by default) of a file to STDOUT.", - * name = "checksum", mixinStandardHelpOptions = true, version = "checksum 3.0") - * class CheckSum implements Callable<Void> { + * name = "checksum", mixinStandardHelpOptions = true, version = "checksum 4.0") + * class CheckSum implements Callable<Integer> { * * @Parameters(index = "0", description = "The file whose checksum to calculate.") * private File file; @@ -117,16 +117,17 @@ * public static void main(String[] args) throws Exception { * // CheckSum implements Callable, so parsing, error handling and handling user * // requests for usage help or version help can be done with one line of code. - * CommandLine.call(new CheckSum(), args); + * int exitCode = new CommandLine(new CheckSum()).execute(args); + * // System.exit(exitCode); * } * * @Override - * public Void call() throws Exception { + * public Integer call() throws Exception { * // your business logic goes here... * byte[] fileContents = Files.readAllBytes(file.toPath()); * byte[] digest = MessageDigest.getInstance(algorithm).digest(fileContents); - * System.out.println(javax.xml.bind.DatatypeConverter.printHexBinary(digest)); - * return null; + * System.out.printf("%0" + (digest.length*2) + "x%n", new BigInteger(1,digest)); + * return 0; * } * } *@@ -784,10 +785,10 @@ public CommandLine setUnmatchedArgumentsAllowed(boolean newValue) { public List
This method is used by {@link #execute(String...)}. - * {@code IParameterExceptionHandler} and {@link IExecutionExceptionHandler} implementations + * {@code IParameterExceptionHandler} and {@link CommandLine.IExecutionExceptionHandler} implementations * should use this stream to print error messages (which may include a usage help message) when an unexpected error occurs. *
* @since 4.0 */ @@ -1035,8 +1036,27 @@ public static interface IParseResultHandler2Implementers responsibilities are:
+ *