Skip to content

Plans and Notes for Future Articles

Remko Popma edited this page May 26, 2019 · 33 revisions

…​ the world needs more picocli articles!

Below is a TODO list of picocli articles to write to make the world a better place.

Tiny, Powerful, Speedy Command Line Apps with Picocli and GraalVM

Kickstarting Tiny, Powerful Command Line Apps with Picocli and GraalVM

CliBuilder Tips and Tricks

Thing possible with CliBuilder since Groovy 2.5.

Picocli v3: Not Your Father’s Command Line Parser

Programmatic API makes it possible to apply picocli in a wide range of applications. One example is that it’s easy to build DSLs (Domain Specific Languages) like Groovy CliBuilder, or use picocli in applications where command line options are defined dynamically. 3.0 also adds support for reuse via Mixins, gives fine-grained control over STDOUT vs STDERR and exit codes. The programmatic API also facilitates the use of picocli in JVM languages where annotations and reflection are not supported or not convenient.

Migrating from Commons CLI to Picocli

Lessons learned while migrating the Groovy command line tools from Commons CLI to picocli.

Interactive CLIs with JLine and Picocli

Using picocli with Dependency Injection containers

Using picocli with JSR-380 Beans Validation

Command Line TAB Autocompletion for Java with Picocli

Java command line applications can now have TAB autocompletion when running on Bash. Now that Windows 10 natively supports Bash, that means pretty much anywhere! This is how you do it…​

ANSI Colors and Style for Kotlin Command Line Apps via Picocli

If you’re creating Kotlin command line applications, you may want to consider using this small library to parse command line options and output a smart-looking usage help message with ANSI colors and styles. Bonus: command line TAB autocompletion.

ANSI Colors and Style for Scala Command Line Apps via Picocli

If you’re creating Scala command line applications, you may want to consider using this small library to parse command line options and output a smart-looking usage help message with ANSI colors and styles. Bonus: command line TAB autocompletion.

Command Line Applications with Subcommands Made Easy with Picocli

Walk through the steps of building a command line application with subcommands. Demonstrates some of the things that picocli makes easy, and some of the things that you need to be aware of. Emphasize the convenience methods and error handling. For example, how to have global options apply to all subcommands. (Related: https://github.com/remkop/picocli/issues/247, https://github.com/remkop/picocli/issues/248, https://github.com/remkop/picocli/issues/175)

Testing Picocli-based Command Line Applications

How do you write unit tests for command line applications built with picocli?

option modifiers

Article on the idea to provide options with a similar prefix that give users different options for authenticating. See discussion in https://github.com/remkop/picocli/issues/176

Good timing for this article may be after https://github.com/remkop/picocli/issues/82 is implemented. We could suggest this in the user manual section on that feature as well.

Example: Sort/Uniq

import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
import picocli.CommandLine.Parameters;

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.LinkedHashMap;
import java.util.concurrent.Callable;
import java.util.stream.Stream;

import static java.util.Comparator.naturalOrder;
import static java.util.Comparator.reverseOrder;
import static java.util.function.Function.identity;
import static java.util.stream.Collectors.counting;
import static java.util.stream.Collectors.groupingBy;

@Command(name = "sort", mixinStandardHelpOptions = true, version = "sort 1.0",
    description = "Sort input lines and write to standard output.")
public class Sort implements Callable<Void> {
    @Parameters(description = "The path to read lines from")
    Path path;

    @Option(names = {"-u", "--unique"}, description = "Output only distinct values")
    boolean unique;

    @Option(names = {"-c", "--count"}, description = "Prefix values by the number of occurrences")
    boolean count;

    @Option(names = {"-r", "--reverse"}, description = "Reverse sort order")
    boolean reverse;

    @Option(names = {"-s", "--skip"}, paramLabel = "NUM", description = "Skip the first NUM values")
    long skip;

    @Override
    public Void call() throws Exception {
        Stream<String> sorted = Files.lines(path).skip(skip).sorted(
                reverse ? reverseOrder() : naturalOrder());
        if (unique) {
            String format = count ? "%d\t%s%n" : "%2$s%n";
            sorted.collect(groupingBy(identity(), LinkedHashMap::new, counting()))
                    .forEach((str, num) -> { System.out.printf(format, num, str); });
        } else {
            sorted.forEach(System.out::println);
        }
        return null;
    }

    public static void main(String[] args) throws Exception {
        CommandLine.call(new Sort(), args);
    }
}
Clone this wiki locally