feat: init commit
This commit is contained in:
38
src/main/java/me/hatter/demo/PicocliCli.java
Normal file
38
src/main/java/me/hatter/demo/PicocliCli.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package me.hatter.demo;
|
||||
|
||||
import picocli.CommandLine;
|
||||
import picocli.CommandLine.Command;
|
||||
import picocli.CommandLine.Option;
|
||||
import picocli.CommandLine.Parameters;
|
||||
import java.io.File;
|
||||
|
||||
@Command(name = "example",
|
||||
mixinStandardHelpOptions = true,
|
||||
version = "Picocli example 1.0")
|
||||
public class PicocliCli {
|
||||
|
||||
@Option(names = {"-v", "--verbose"},
|
||||
description = "Verbose mode. Helpful for troubleshooting. Multiple -v options increase the verbosity.")
|
||||
private boolean[] verbose = new boolean[0];
|
||||
|
||||
@Parameters(arity = "1..*", paramLabel = "FILE", description = "File(s) to process.")
|
||||
private File[] inputFiles;
|
||||
|
||||
public void run() {
|
||||
if (verbose.length > 0) {
|
||||
System.out.println(inputFiles.length + " files to process...");
|
||||
}
|
||||
if (verbose.length > 1) {
|
||||
for (File f : inputFiles) {
|
||||
System.out.println(f.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// By implementing Runnable or Callable, parsing, error handling and handling user
|
||||
// requests for usage help or version help can be done with one line of code.
|
||||
int exitCode = new CommandLine(new PicocliCli()).execute(args);
|
||||
System.exit(exitCode);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user