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
@@ -859,15 +861,17 @@ usage help or version information was requested (without inspecting the annotate
859
861
CommandLine commandLine = new CommandLine(new App());
860
862
commandLine.parse(args);
861
863
if (commandLine.isUsageHelpRequested()) {
862
-
commandLine.usage(System.err);
864
+
commandLine.usage(System.out);
863
865
return;
864
866
} else if (commandLine.isVersionHelpRequested()) {
865
-
commandLine.printVersionHelp(System.err);
867
+
commandLine.printVersionHelp(System.out);
866
868
return;
867
869
}
868
870
----
869
871
870
-
From picocli v2.0, the <<Less Boilerplate,convenience methods>> will automatically print usage help and version information when requested with the `versionHelp` and `usageHelp` option attributes (but not for the `help` attribute).
872
+
From picocli v2.0, the <<Less Boilerplate,convenience methods>> will automatically print usage help and version information
873
+
when requested with the `versionHelp` and `usageHelp` option attributes (but not for the `help` attribute).
874
+
From v2.0, the `help` attribute is deprecated.
871
875
872
876
Methods that automatically print help:
873
877
@@ -902,7 +906,7 @@ annotation and prints it to the specified `PrintStream`.
902
906
CommandLine commandLine = new CommandLine(new VersionedCommand());
903
907
commandLine.parse(args);
904
908
if (commandLine.isVersionHelpRequested()) {
905
-
commandLine.printVersionHelp(System.err);
909
+
commandLine.printVersionHelp(System.out);
906
910
return;
907
911
}
908
912
----
@@ -952,14 +956,20 @@ Format argument values can be passed to the `printVersionHelp` method:
Note that the positional parameters are not abbreviated.
1079
1089
[source,java]
1080
1090
----
1081
-
@CommandLine.Command(abbreviateSynopsis = true)
1091
+
@Command(abbreviateSynopsis = true)
1082
1092
class App {
1083
1093
@Parameters File[] files;
1084
1094
@Option(names = {"--count", "-c"}) int count;
@@ -1119,7 +1129,7 @@ The `headerHeading` and `footerHeading` may contain format specifiers. See <<Sec
1119
1129
Section headers can be used to make usage message layout appear more spacious. Section headings may contain embedded line separator (`%n`) format specifiers:
1120
1130
[source,java]
1121
1131
----
1122
-
@CommandLine.Command(name = "git-commit",
1132
+
@Command(name = "git-commit",
1123
1133
sortOptions = false,
1124
1134
headerHeading = "Usage:%n%n",
1125
1135
synopsisHeading = "%n",
@@ -1631,7 +1641,13 @@ class FileUtils {
1631
1641
description = "this option applies to all subcommands")
1632
1642
File baseDirectory;
1633
1643
}
1644
+
----
1645
+
1646
+
The above top-level command has a `--directory` option that applies to its subcommands.
1647
+
The `List` subcommand can use the `@ParentCommand` annotation to get a reference to the parent command, so it can easily access the parent command options.
1634
1648
1649
+
[source,java]
1650
+
----
1635
1651
@Command(name = "list")
1636
1652
class List implements Runnable {
1637
1653
@@ -1673,6 +1689,7 @@ CommandLine commandLine = new CommandLine(new Git());
1673
1689
// add subcommands programmatically (not necessary if the parent command
1674
1690
// declaratively registers the subcommands via annotation)
1675
1691
commandLine.addSubcommand("status", new GitStatus());
1692
+
commandLine.addSubcommand("commit", new GitCommit());
1676
1693
...
1677
1694
commandLine.usage(System.out);
1678
1695
----
@@ -1785,10 +1802,10 @@ CommandLine cmd = new CommandLine(callable);
1785
1802
try {
1786
1803
cmd.parse(args);
1787
1804
if (cmd.isUsageHelpRequested()) {
1788
-
cmd.usage(System.err);
1805
+
cmd.usage(System.out);
1789
1806
return null;
1790
1807
} else if (cmd.isVersionHelpRequested()) {
1791
-
cmd.printVersionHelp(System.err);
1808
+
cmd.printVersionHelp(System.out);
1792
1809
return null;
1793
1810
}
1794
1811
return callable.call();
@@ -1834,7 +1851,7 @@ CommandLine cmd = new CommandLine(MyTopLevelCommand())
1834
1851
.addSubcommand("status", new GitStatus())
1835
1852
.addSubcommand("commit", new GitCommit())
1836
1853
.addSubcommand("add", new GitAdd());
1837
-
List<Object result = cmd.parseWithHandler(new RunAll(), System.err, args);
1854
+
List<Object> result = cmd.parseWithHandler(new RunAll(), System.err, args);
1838
1855
----
1839
1856
1840
1857
The `CommandLine::parseWithHandler` method will take care of the following:
0 commit comments