|
@@ -0,0 +1,40 @@
|
|
|
|
+package com.alvin;
|
|
|
|
+
|
|
|
|
+import picocli.CommandLine;
|
|
|
|
+
|
|
|
|
+public class Main {
|
|
|
|
+ public static void main(String[] args) {
|
|
|
|
+ // 解析参数
|
|
|
|
+ final CmdParam cmdParam = new CmdParam();
|
|
|
|
+ final CommandLine commandLine = new CommandLine(cmdParam);
|
|
|
|
+ try {
|
|
|
|
+ final CommandLine.ParseResult parseResult = commandLine.parseArgs(args);
|
|
|
|
+ checkParamHelp(args.length == 0, commandLine, parseResult);
|
|
|
|
+ if (parseResult.hasSubcommand()) {
|
|
|
|
+ for (CommandLine.ParseResult subCommand : parseResult.subcommands()) {
|
|
|
|
+ final CommandLine c = subCommand.commandSpec().commandLine();
|
|
|
|
+ checkParamHelp(args.length == 1, c, subCommand);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch (CommandLine.ParameterException e) {
|
|
|
|
+ commandLine.usage(System.out);
|
|
|
|
+ for (CommandLine c : commandLine.getSubcommands().values()) {
|
|
|
|
+ c.usage(System.out);
|
|
|
|
+ }
|
|
|
|
+ System.exit(1);
|
|
|
|
+ }
|
|
|
|
+ System.out.println("cmd params: " + cmdParam);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static void checkParamHelp(boolean empty, CommandLine commandLine, CommandLine.ParseResult parseResult) {
|
|
|
|
+ if (empty || parseResult.isUsageHelpRequested()) {
|
|
|
|
+ commandLine.usage(System.out);
|
|
|
|
+ System.exit(0);
|
|
|
|
+ }
|
|
|
|
+ if (parseResult.isVersionHelpRequested()) {
|
|
|
|
+ commandLine.printVersionHelp(System.out);
|
|
|
|
+ System.exit(0);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|