/** {@inheritDoc} */ @Override public void run() { CommandLine.usage(this, System.out); } }
@Override public void run() { CommandLine.usage(this, System.out); } }
/** * Delegates to {@link #usage(PrintStream, Help.Ansi)} with the {@linkplain Help.Ansi#AUTO platform default}. * @param out the printStream to print to * @see #usage(PrintStream, Help.ColorScheme) */ public void usage(PrintStream out) { usage(out, Help.Ansi.AUTO); } /**
/** * Delegates to {@link #usage(PrintWriter, Help.Ansi)} with the {@linkplain Help.Ansi#AUTO platform default}. * @param writer the PrintWriter to print to * @see #usage(PrintWriter, Help.ColorScheme) * @since 3.0 */ public void usage(PrintWriter writer) { usage(writer, Help.Ansi.AUTO); }
private boolean checkExists(final File file) { if (file.exists()) { System.err.printf("ERROR: picocli.AutoComplete: %s exists. Specify --force to overwrite.%n", file.getAbsolutePath()); CommandLine.usage(this, System.err); return true; } return false; } }
private void showSimpleExampleUsage() { class Example { @Option(names = { "-v", "--verbose" }, description = "Be verbose.") private boolean verbose = false; @Option(names = { "-h", "--help" }, help = true, description = "Displays this help message and quits.") private boolean helpRequested = false; @Parameters(arity = "1..*", paramLabel = "FILE", description = "File(s) to process.") private File[] inputFiles; } CommandLine.usage(new Example(), System.out); }
/** * Delegates to {@link #usage(PrintStream, Help.ColorScheme)} with the {@linkplain Help#defaultColorScheme(CommandLine.Help.Ansi) default color scheme}. * @param out the printStream to print to * @param ansi whether the usage message should include ANSI escape codes or not * @see #usage(PrintStream, Help.ColorScheme) */ public void usage(PrintStream out, Help.Ansi ansi) { usage(out, Help.defaultColorScheme(ansi)); } /** Similar to {@link #usage(PrintStream, Help.Ansi)} but with the specified {@code PrintWriter} instead of a {@code PrintStream}.
/** * Equivalent to {@code new CommandLine(command).usage(out, colorScheme)}. * See {@link #usage(PrintStream, Help.ColorScheme)} for details. * @param command the object annotated with {@link Command}, {@link Option} and {@link Parameters} * @param out the print stream to print the help message to * @param colorScheme the {@code ColorScheme} defining the styles for options, parameters and commands when ANSI is enabled * @throws IllegalArgumentException if the specified command object does not have a {@link Command}, {@link Option} or {@link Parameters} annotation */ public static void usage(Object command, PrintStream out, Help.ColorScheme colorScheme) { toCommandLine(command, new DefaultFactory()).usage(out, colorScheme); }
/** * Equivalent to {@code new CommandLine(command).usage(out)}. See {@link #usage(PrintStream)} for details. * @param command the object annotated with {@link Command}, {@link Option} and {@link Parameters} * @param out the print stream to print the help message to * @throws IllegalArgumentException if the specified command object does not have a {@link Command}, {@link Option} or {@link Parameters} annotation */ public static void usage(Object command, PrintStream out) { toCommandLine(command, new DefaultFactory()).usage(out); }
/** Similar to {@link #usage(PrintStream, Help.ColorScheme)}, but with the specified {@code PrintWriter} instead of a {@code PrintStream}. * @since 3.0 */ public void usage(PrintWriter writer, Help.ColorScheme colorScheme) { writer.print(usage(new StringBuilder(), getHelpFactory().create(getCommandSpec(), colorScheme))); } /** Similar to {@link #usage(PrintStream)}, but returns the usage help message as a String instead of printing it to the {@code PrintStream}.
/** Similar to {@link #usage(PrintStream, Help.ColorScheme)}, but returns the usage help message as a String instead of printing it to the {@code PrintStream}. * @since 3.2 */ public String getUsageMessage(Help.ColorScheme colorScheme) { return usage(new StringBuilder(), getHelpFactory().create(getCommandSpec(), colorScheme)).toString(); }
/** Similar to {@link #usage(PrintStream, Help.Ansi)}, but returns the usage help message as a String instead of printing it to the {@code PrintStream}. * @since 3.2 */ public String getUsageMessage(Help.Ansi ansi) { return usage(new StringBuilder(), getHelpFactory().create(getCommandSpec(), Help.defaultColorScheme(ansi))).toString(); } /** Similar to {@link #usage(PrintStream, Help.ColorScheme)}, but returns the usage help message as a String instead of printing it to the {@code PrintStream}.
private void internalHandleParseException(ParameterException ex, PrintStream out, Help.Ansi ansi, String[] args) { out.println(ex.getMessage()); if (!UnmatchedArgumentException.printSuggestions(ex, out)) { ex.getCommandLine().usage(out, ansi); } } /** This implementation always simply rethrows the specified exception.
/** Similar to {@link #usage(PrintStream)}, but returns the usage help message as a String instead of printing it to the {@code PrintStream}. * @since 3.2 */ public String getUsageMessage() { return usage(new StringBuilder(), getHelpFactory().create(getCommandSpec(), Help.defaultColorScheme(Help.Ansi.AUTO))).toString(); } /** Similar to {@link #usage(PrintStream, Help.Ansi)}, but returns the usage help message as a String instead of printing it to the {@code PrintStream}.
public void testUsageSubCommandStatus() { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); CommandLine.usage(new GitStatus(), new PrintStream(baos, true, "UTF8")); String result = baos.toString("UTF8"); System.out.println(result); assert String.format(EXPECTED_USAGE_GITSTATUS).equals(result); } catch (UnsupportedEncodingException ex) { throw new InternalError(ex.toString()); } } static final String EXPECTED_USAGE_GITSTATUS = "Show the working tree status.%n" +
public void testUsageSubCommandCommit() { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); CommandLine.usage(new GitCommit(), new PrintStream(baos, true, "UTF8")); String result = baos.toString("UTF8"); System.out.println(result); assert String.format(EXPECTED_USAGE_GITCOMMIT).equals(result); } catch (UnsupportedEncodingException ex) { throw new InternalError(ex.toString()); } } static final String EXPECTED_USAGE_GITCOMMIT = "Usage:%n" +
@Test(expected = InitializationException.class) public void testUsageObjectPrintstreamAnsiRequiresAnnotatedCommand() { class App { } CommandLine.usage(new App(), System.out, Help.Ansi.OFF); }
public void run() { if (!showZip && !showNetstat) { CommandLine.usage(this, System.err); return; } if (showZip) { System.out.println(createZipUsageFormat(Help.Ansi.AUTO)); } if (showNetstat) { System.out.println(createNetstatUsageFormat(Help.Ansi.AUTO)); } }
@Test(expected = InitializationException.class) public void testUsageObjectPrintstreamColorschemeRequiresAnnotatedCommand() { class App { } CommandLine.usage(new App(), System.out, Help.defaultColorScheme(Help.Ansi.OFF)); }
public static void main(String[] args) { CommandLine cmd = new CommandLine(new ParentCommand()); cmd.parseWithHandler(new CommandLine.RunAll(), args); if (args.length == 0) { cmd.usage(System.out); } } }