- Overview
- Package
- Class
- Tree
- Deprecated
- Index
- Help

- Prev
- Next

- Frames
- No Frames

- All Classes

# picocli 2.3.0 API

Picocli is a one-file framework for creating Java command line applications with almost zero code.

See: Description

Packages
picocli: Provides classes and interfaces for the main picocli command line parsing and `autocompletion` functionality.
picocli.groovy: Provides classes and annotations to give Groovy scripts convenient access to picocli functionality.

Picocli is a one-file framework for creating Java command line applications with almost zero code. It supports a variety of command line syntax styles including POSIX, GNU, MS-DOS and more. Generates highly customizable usage help messages with ANSI colors and styles. Picocli-based applications can have command line TAB completion showing available options, option parameters and subcommands, for any level of nested subcommands.

How it works: annotate your class and picocli initializes it from the command line arguments, converting the input to strongly typed values in the fields of your class. Then invoke `CommandLine.parse` or `CommandLine.populateCommand` with the command line parameters and an object you want to initialize.

Picocli provides a number of convenience methods that allow you to omit error handling and other boilerplate code for common use cases. Here is a small example application that uses the `CommandLine.call` convenience method to do parsing and error handling in one line of code.

The full user manual is hosted at http://picocli.info.

    @Command(name = "checksum", description = "Prints the checksum (MD5 by default) of a file to STDOUT.")
    class CheckSum implements Callable<Void> {

        @Parameters(index = "0", description = "The file whose checksum to calculate.")
        private File file;

        @Option(names = {"-a", "--algorithm"}, description = "MD5, SHA-1, SHA-256, ...")
        private String algorithm = "MD5";

        @Option(names = {"-h", "--help"}, usageHelp = true, description = "Show this help message and exit.")
        private boolean helpRequested;

        public static void main(String[] args) throws Exception {
            // CheckSum implements Callable, so parsing, error handling and handling user
            // requests for usage help or version help can be done with one line of code.
            CommandLine.call(new CheckSum(), System.err, args);
        }

        @Override
        public Void call() throws Exception {
            // your business logic goes here
            byte[] fileContents = Files.readAllBytes(file.toPath());
            byte[] digest = MessageDigest.getInstance(algorithm).digest(fileContents);
            System.out.println(javax.xml.bind.DatatypeConverter.printHexBinary(digest));
            return null;
        }
    }

- Overview
- Package
- Class
- Tree
- Deprecated
- Index
- Help

- Prev
- Next

- Frames
- No Frames

- All Classes