diff options
| author | J08nY | 2018-10-15 18:16:03 +0200 |
|---|---|---|
| committer | J08nY | 2018-10-15 18:16:03 +0200 |
| commit | ee13937d70383e925cf32858e73d89a6c18bf7f0 (patch) | |
| tree | fa3f8dfd255b8a24d15dd1734fe327df56b8ac2c /src/cz/crcs/ectester/common/cli/CLITools.java | |
| parent | d24630d759bb16f715564ab80a5d4447f57d03f2 (diff) | |
| parent | ea4e807906815c16c62c4e5719950c7274d1ebab (diff) | |
| download | ECTester-ee13937d70383e925cf32858e73d89a6c18bf7f0.tar.gz ECTester-ee13937d70383e925cf32858e73d89a6c18bf7f0.tar.zst ECTester-ee13937d70383e925cf32858e73d89a6c18bf7f0.zip | |
Diffstat (limited to 'src/cz/crcs/ectester/common/cli/CLITools.java')
| -rw-r--r-- | src/cz/crcs/ectester/common/cli/CLITools.java | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/cz/crcs/ectester/common/cli/CLITools.java b/src/cz/crcs/ectester/common/cli/CLITools.java index a9d036e..82ab530 100644 --- a/src/cz/crcs/ectester/common/cli/CLITools.java +++ b/src/cz/crcs/ectester/common/cli/CLITools.java @@ -25,6 +25,12 @@ public class CLITools { help.printHelp(Colors.bold(prog), header, options, footer, usage); } + private static void help(HelpFormatter help, PrintWriter pw, String cmd, ParserOptions parser, int depth) { + String description = parser.getDescription() == null ? "" : " | " + parser.getDescription() + " |"; + help.printWrapped(pw, HelpFormatter.DEFAULT_WIDTH, String.format("%" + depth + "s" + cmd + ":" + description, " ")); + CLITools.help(help, pw, parser.getParser(), parser.getOptions(), depth + 1); + } + private static void help(HelpFormatter help, PrintWriter pw, CommandLineParser cli, Options opts, int depth) { if (opts.getOptions().size() > 0) { help.printOptions(pw, HelpFormatter.DEFAULT_WIDTH, opts, HelpFormatter.DEFAULT_LEFT_PAD + depth, HelpFormatter.DEFAULT_DESC_PAD); @@ -37,9 +43,7 @@ public class CLITools { } tp.getParsers().forEach((key, value) -> { pw.println(); - String description = value.getDescription() == null ? "" : " | " + value.getDescription() + " |"; - help.printWrapped(pw, HelpFormatter.DEFAULT_WIDTH, String.format("%" + depth + "s" + key + ":" + description, " ")); - CLITools.help(help, pw, value.getParser(), value.getOptions(), depth + 1); + help(help, pw, key, value, depth); }); } } @@ -107,6 +111,22 @@ public class CLITools { System.out.println(sw.toString()); } + public static void help(String header, TreeParser baseParser, String footer, String command) { + ParserOptions opts = baseParser.getParsers().get(command); + if (opts == null) { + System.err.println("Command not found: " + command); + return; + } + HelpFormatter help = new HelpFormatter(); + help.setOptionComparator(null); + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + help.printWrapped(pw, HelpFormatter.DEFAULT_WIDTH, header); + help(help, pw, command, opts, 1); + help.printWrapped(pw, HelpFormatter.DEFAULT_WIDTH, footer); + System.out.println(sw.toString()); + } + /** * Print version info. */ |
