GithubHelp home page GithubHelp logo

remkop / picocli Goto Github PK

View Code? Open in Web Editor NEW
4.8K 4.8K 414.0 82.73 MB

Picocli is a modern framework for building powerful, user-friendly, GraalVM-enabled command line apps with ease. It supports colors, autocompletion, subcommands, and more. In 1 source file so apps can include as source & avoid adding a dependency. Written in Java, usable from Groovy, Kotlin, Scala, etc.

Home Page: https://picocli.info

License: Apache License 2.0

Java 95.84% Shell 1.85% Groovy 1.60% HTML 0.06% Kotlin 0.52% Scala 0.12%
annotations ansi ansi-colors argument-parsing autocomplete bash-completion cli cli-framework command-line command-line-parser commandline completion executable git graalvm java native-image options-parsing parser subcommands

picocli's People

Contributors

ahmede41 avatar bbottema avatar bdemers avatar charphi avatar christrenkamp avatar crotwell avatar danielthegray avatar deining avatar dependabot[bot] avatar dwalluck avatar goooler avatar illes avatar jerrylususu avatar jsotuyod avatar licia-tia avatar madfoal avatar markomackic avatar mattirn avatar mikethesnowman avatar newbieorange avatar nicolasmassart avatar querqueq avatar reallinfo avatar remkop avatar rgoldberg avatar rsenden avatar sualeh avatar tisonkun avatar triceo avatar vorburger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

picocli's Issues

Should CommandLine offer a "starter" function?

Current full usage is:

public static void main(String... args) {
   try {
       MyClass myClass = CommandLine.parse(new MyClass(), args);
       if (myClass.help) {
           CommandLine.usage(MyClass.class, System.out);
       } else if (myClass.version) {
           System.out.println("MyProgram version 1.2.3");
       } else {
           runProgram(myClass);
       }
   } catch (ParameterException ex) { // command line arguments could not be parsed
       System.err.println(ex.getMessage());
       CommandLine.usage(MyClass.class, System.err);
   }
}

Can we reduce the try/catch boilerplate with a convenience method?

public static void main(String... args) {
   MyClass myClass = CommandLine.parseOrPrintUsage(new MyClass(), System.err, args);
   if (myClass == null) { // parsing failed
       return; 
   }
   if (myClass.help) {
       CommandLine.usage(MyClass.class, System.out);
   } else if (myClass.version) {
       System.out.println("MyProgram version 1.2.3");
   } else {
       runProgram(myClass);
   }
}

Array field values should be preserved (like Collections) and new values appended

Currently array fields (Params or option) are always initialized to a new array instance, regardless of what the current value is.

Collections however are only instantiated when they are initially null, otherwise values are added to the original collection instance.

This asymmetry is undesirable.

Note: we may want to support map-like options like -Da=b -Dx=y. Behaviour for map-like containers should be consistent with arrays and collections.

@Option should not greedily consume args if varargs=false

Example

@Option(names="-words") String[] words;
@Option(names="-v") boolean verbose;

Given command line args -words a b c -v,
the current implementation interprets the "-v" as one of the parameters for word.

An application using picoCLI should be able to designate whether arguments following the option should be greedily consumed or not. This is what the varargs attribute is for. The default for @option is false (as it should be), but the implemented behavior is different.

Detailed usage header should cluster boolean options

Example:

usage: nc [-46CDdhklnrtUuvz] [-I length] [-i interval] [-O length]
          [-P proxy_username] [-p source_port] [-s source] [-T ToS]
          [-V rtable] [-w timeout] [-X proxy_protocol]
          [-x proxy_address[:port]] [destination] [port]

i18n

Ideas:

  • @option(..., i18nKey="myKey") -look up myKey in ResourceBundle
  • @option(..., description="A b c d") -look up A_b_c_d in ResourceBundle
  • look up fully qualified field name in ResourceBundle

Consider adjusting the column width of the 3rd (long options) column based on the longest value.

The default Columns in a TextTable have a fixed predefined width.
The 3rd column is 24 characters wide by default. Consider adjusting this to a smaller value if all values are less than this width, or if 80-90% of values are less than this width.

Potential drawback is that it may be less predictable for applications to write their description lines in a way that lays out nicely.

Add positional @Parameter annotation

This allows positional parameters to be assigned to separate fields with separate types.
usage example: <program> "header text" file1 23 file2 43

class Args {
  @Parameter(position=0, helpText="header text")       String headerText;
  @Parameter(position=1, helpText="binary input file") File binaryInput;
  @Parameter(position=2, helpText="record length")     int recordLength;
  @Parameter(position=3, helpText="text output file")  File output;
  @Parameter(position=4, helpText="max output lines")  int maxLines;
  ...
}

Definition:

@Parameter {
  int position;
  boolean required;
  String helpText;
  boolean hidden;
}

(Introduce a "positional parameters in progress" field?)

Create comparison feature table with prior art

Support customizable user help format.

Ideally programmers should be able to specify a UsageFormatter interface implementation that gives complete freedom over the usage message layout.

Expose picoCLI usage layout functionality so custom formatters can reuse it.

Customizable:

  • "Usage" line: mention option short form with [-v] optional and mandatory elements, or a generic [OPTIONS] [PARAMETERS]
  • option columns: show in declared order or sort short options first
  • option rows: sort alphabetically or show in declared order
  • required options: show '*' in front of option name, or print 'Required' on 2nd line or print '(Required)' before or after the option description
  • option parameter name: use field name or use field type (class SimpleName)
  • option and parameter separated by space or by '='
  • option parameter default value: print 'Default: VALUE' on 2nd line or print '(default: VALUE)' after the option description

Interpreter should set helpRequested=false before parse()

A CommandLine instance may be reused to parse multiple command line arrays. Ensure any state in the Interpreter is reset to the default at the start of the parse() method.
Especially if a "positional parameters in progress" field is introduced for the proposed @parameter annotation.

Write user manual

  • options vs positional parameters
  • standalone options are booleans
  • options can take parameters
  • parameters are strongly typed
  • built-in type converters
  • registering custom type converters
  • option short form
  • short form options can be grouped
  • last option in a short option group can take a parameter
  • varargs
  • optional parameters
  • use arity to specify number of required parameters
    (Only allows min, consider supporting max also)
  • option parameters are separated from option name or attached with configurable separator '='

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.