Skip to content

Commit

Permalink
[#299][#459] gen-manpage improvements: add Exit Codes section to usag…
Browse files Browse the repository at this point in the history
…e help; improve error message
  • Loading branch information
remkop committed Feb 11, 2020
1 parent b4b844f commit 9038b71
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import static java.lang.String.format;

public class ManPageGenerator {
static final int EXIT_CODE_FILE_EXISTS = 4;
static final int EXIT_CODE_TEMPLATE_EXISTS = 4;

static final IStyle BOLD = new IStyle() {
public String on() { return "*"; }
Expand Down Expand Up @@ -101,6 +101,15 @@ private void verboseDetailed(String message, Object... params) {
version = "picocli-codegen ${COMMAND-NAME} " + CommandLine.VERSION, showAtFileInUsageHelp = true,
mixinStandardHelpOptions = true, sortOptions = false, usageHelpAutoWidth = true, usageHelpWidth = 100,
description = {"Generates one or more AsciiDoc files with doctype 'manpage' in the specified directory."},
exitCodeListHeading = "%nExit Codes:%n",
exitCodeList = {
"0:Successful program execution",
"1:A runtime exception occurred while generating man pages.",
"2:Usage error: user input for the command was incorrect, " +
"e.g., the wrong number of arguments, a bad flag, " +
"a bad syntax in a parameter, etc.",
"4:A template file exists in the template directory (Specify `--force` to overwrite)."
},
footerHeading = "%nConverting to Man Page Format%n%n",
footer = {"Use the `asciidoctor` tool to convert the generated AsciiDoc files to man pages in roff format:",
"",
Expand Down Expand Up @@ -202,7 +211,7 @@ private static int generateSingleManPage(Config config, CommandSpec spec) throws

generateSingleManPage(spec, manpage);

return generateCustomizableManPageTemplate(config, spec);
return generateCustomizableTemplate(config, spec);
}

private static boolean mkdirs(Config config, File directory) {
Expand Down Expand Up @@ -235,7 +244,7 @@ private static void generateSingleManPage(CommandSpec spec, File manpage) throws
}
}

private static int generateCustomizableManPageTemplate(Config config, CommandSpec spec) throws IOException {
private static int generateCustomizableTemplate(Config config, CommandSpec spec) throws IOException {
if (config.templatesDirectory == null) {
return CommandLine.ExitCode.OK;
}
Expand All @@ -248,9 +257,10 @@ private static int generateCustomizableManPageTemplate(Config config, CommandSpe
if (config.force) {
config.verbose("Overwriting existing man page template file %s...%n", templateFile);
} else {
System.err.printf("gen-manpage: ERROR: cannot generate man page template file %s: it already exists. Use --force to overwrite.%n", templateFile);
System.err.printf("gen-manpage: ERROR: cannot generate man page template file %s: it already exists. " +
"Remove the --template-dir option or use --force to overwrite.%n", templateFile);
System.err.println("Try 'gen-manpage --help' for more information.");
return EXIT_CODE_FILE_EXISTS;
return EXIT_CODE_TEMPLATE_EXISTS;
}
} else {
config.verbose("Generating customizable man page template %s%n", templateFile);
Expand Down

0 comments on commit 9038b71

Please sign in to comment.