2

We develop a Java Cli application, that has sub-commands with similar options. It's like svn:

svn commit -m messsage --username ARG --password ARG
svn checkout -r HEAD --username ARG --password ARG

I mean that each subcommand has special arguments, and we have also global arguments, and we have some arguments that are relvant for some subcommands, but not for all.

Which command line arguments parser supports that requirements?

thank you.

2

1 Answer 1

5

picocli supports nested subcommands to arbitrary depth.

The main command defines global options, each following level of nested commands can add options that only apply to that level.

CommandLine commandLine = new CommandLine(new MainCommand())
        .addSubcommand("cmd1", new ChildCommand1()) // 1st level
        .addSubcommand("cmd2", new ChildCommand2())
        .addSubcommand("cmd3", new CommandLine(new ChildCommand3()) // 2nd level
                .addSubcommand("cmd3sub1", new GrandChild3Command1())
                .addSubcommand("cmd3sub2", new GrandChild3Command2())
                .addSubcommand("cmd3sub3", new CommandLine(new GrandChild3Command3()) // 3rd
                        .addSubcommand("cmd3sub3sub1", new GreatGrandChild3Command3_1())
                        .addSubcommand("cmd3sub3sub2", new GreatGrandChild3Command3_2())
                                // etc
                )
        );

You may also like its usage help with ANSI styles and colors.

Usage help lists the registered subcommands in addition to options and positional parameters.

enter image description here

The usage help is easily customized with annotations.

enter image description here

  • annotation-based
  • git-style subcommands
  • nested sub-subcommands
  • strongly typed option parameters
  • strongly typed positional parameters
  • customizable type conversion
  • multi-value options
  • intuitive model for how many arguments a field consumes
  • fluent API
  • POSIX-style clustered short options
  • GNU style long options
  • allows any option prefix
  • ANSI colors in usage help
  • customizable usage help
  • single source file: include as source to keep your application a single jar
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.