You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add convenience API example to CommandLine class Javadoc.
* <p>
* 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:
* </p>
* <pre>
* @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> {
*
* @Parameters(index = "0", description = "The file whose checksum to calculate.")
* private File file;
*
* @Option(names = {"-a", "--algorithm"}, description = "MD5, SHA-1, SHA-256, ...")
* private String algorithm = "MD5";
*
* 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);
* }
*
* @Override
* public Void 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;
* }
* }
* </pre>
The text was updated successfully, but these errors were encountered:
Add convenience API example to CommandLine class Javadoc.
The text was updated successfully, but these errors were encountered: