Skip to content

Commit e302194

Browse files
remkopMarkoMackic
authored andcommitted
[remkop#1348] example of reverse synopsis
1 parent 233bf48 commit e302194

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package picocli.examples.synopsis;
2+
3+
import picocli.CommandLine;
4+
import picocli.CommandLine.Command;
5+
import picocli.CommandLine.Help.ColorScheme;
6+
import picocli.CommandLine.Model.CommandSpec;
7+
import picocli.CommandLine.Option;
8+
import picocli.CommandLine.Parameters;
9+
10+
import java.io.File;
11+
12+
/**
13+
* See https://github.com/remkop/picocli/issues/1348
14+
*/
15+
@Command(name = "rename")
16+
public class ParametersBeforeOptions implements Runnable {
17+
@Parameters
18+
File file;
19+
20+
@Option(names = "to", required = true)
21+
File new_file;
22+
23+
@Override
24+
public void run() {
25+
// business logic
26+
}
27+
28+
public static void main(String... args) {
29+
new CommandLine(new ParametersBeforeOptions())
30+
.setHelpFactory(new ReverseSynopsisHelpFactory())
31+
.execute("-h");
32+
}
33+
}
34+
35+
class ReverseSynopsisHelpFactory implements CommandLine.IHelpFactory {
36+
37+
@Override
38+
public CommandLine.Help create(CommandSpec commandSpec, ColorScheme colorScheme) {
39+
return new CommandLine.Help(commandSpec, colorScheme) {
40+
@Override
41+
protected String makeSynopsisFromParts(int synopsisHeadingLength, Ansi.Text optionText, Ansi.Text groupsText, Ansi.Text endOfOptionsText, Ansi.Text positionalParamText, Ansi.Text commandText) {
42+
return super.makeSynopsisFromParts(synopsisHeadingLength, positionalParamText, groupsText, endOfOptionsText, optionText, commandText);
43+
}
44+
};
45+
}
46+
}

0 commit comments

Comments
 (0)