-
Notifications
You must be signed in to change notification settings - Fork 429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Documentation: improvements #1171
Changes from all commits
a210b63
ba2e0a1
6781931
d262b6e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,20 @@ | |
:toc: left | ||
:numbered: | ||
:toclevels: 2 | ||
:toc-title: Features | ||
:toc-title: Table of contents | ||
:source-highlighter: coderay | ||
//:source-highlighter: highlightjs | ||
//:highlightjs-theme: darkula | ||
:icons: font | ||
:imagesdir: images | ||
:sectanchors: | ||
ifdef::env-github[] | ||
:caution-caption: :fire: | ||
:important-caption: :heavy_exclamation_mark: | ||
:note-caption: :information_source: | ||
:tip-caption: :bulb: | ||
:warning-caption: :warning: | ||
endif::[] | ||
|
||
[link=https://github.com/remkop/picocli] | ||
image::https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png[Fork me on GitHub,float="right"] | ||
|
@@ -28,31 +35,29 @@ image:logo/horizontal.png[picocli the Mighty Tiny Command Line Interface,width=8 | |
The user manual for the latest release is at http://picocli.info. | ||
For the busy and impatient: there is also a link:quick-guide.html[Quick Guide]. | ||
|
||
== Introduction | ||
== Introducing Picocli | ||
Picocli is a one-file framework for creating Java command line applications with almost zero code. | ||
Picocli aims to be the easiest way to create rich command line applications that can run on and off the JVM. | ||
|
||
Picocli is a one-file framework for creating Java command line applications with almost zero code. | ||
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,ANSI colors and styles>>. | ||
=== Features | ||
Picocli supports a variety of command line syntax styles including POSIX, GNU, MS-DOS and more and generates highly customizable usage help messages with <<ANSI Colors and Styles,ANSI colors and styles>>. | ||
Picocli-based applications can have link:autocomplete.html[command line TAB completion] showing available options, option parameters and subcommands, for any level of nested subcommands. | ||
Picocli-based applications can be ahead-of-time compiled to a image:https://www.graalvm.org/resources/img/logo-colored.svg[GraalVM] | ||
<<GraalVM Native Image,native image>>, with extremely fast startup time and lower memory requirements, which can be distributed as a single executable file. | ||
|
||
|
||
image:checksum-usage-help.png[Screenshot of usage help with Ansi codes enabled] | ||
|
||
Picocli <<Generate Man Page Documentation,generates beautiful documentation>> for your application (HTML, PDF and Unix man pages). | ||
|
||
Another distinguishing feature of picocli is how it aims | ||
to let users run picocli-based applications without requiring picocli as an external dependency: | ||
all the source code lives in a single file, to encourage application authors to include it _in source form_. | ||
|
||
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. | ||
=== Sample application | ||
Let's get started by looking at minimal picocli-based command line application. This fully working sample app may be used to calculate the checksum(s) of one or more file(s) given as command line parameter(s): | ||
|
||
TIP: picocli also provides a <<Programmatic API,programmatic API>>, separately from the annotations API. | ||
.Synopsis of sample application | ||
image:checksum-usage-help.png[Screenshot of usage help with Ansi codes enabled] | ||
|
||
.A full working example picocli-based command line application | ||
.Source code of sample application | ||
[[CheckSum-application]] | ||
[source,java] | ||
---- | ||
|
@@ -67,25 +72,25 @@ import java.nio.file.Files; | |
import java.security.MessageDigest; | ||
import java.util.concurrent.Callable; | ||
|
||
@Command(name = "checksum", mixinStandardHelpOptions = true, version = "checksum 4.0", | ||
@Command(name = "checksum", mixinStandardHelpOptions = true, version = "checksum 4.0", // <8> | ||
description = "Prints the checksum (MD5 by default) of a file to STDOUT.") | ||
class CheckSum implements Callable<Integer> { | ||
class CheckSum implements Callable<Integer> { // <1> | ||
|
||
@Parameters(index = "0", description = "The file whose checksum to calculate.") | ||
private File file; | ||
@Parameters(index = "0", description = "The file whose checksum to calculate.") // <2> | ||
private File file; // <4> | ||
|
||
@Option(names = {"-a", "--algorithm"}, description = "MD5, SHA-1, SHA-256, ...") | ||
private String algorithm = "MD5"; | ||
@Option(names = {"-a", "--algorithm"}, description = "MD5, SHA-1, SHA-256, ...") // <3> | ||
private String algorithm = "MD5"; // <4> | ||
|
||
// this example implements Callable, so parsing, error handling and handling user | ||
// requests for usage help or version help can be done with one line of code. | ||
public static void main(String... args) { | ||
int exitCode = new CommandLine(new CheckSum()).execute(args); | ||
System.exit(exitCode); | ||
int exitCode = new CommandLine(new CheckSum()).execute(args); // <5> | ||
System.exit(exitCode); // <7> | ||
} | ||
|
||
@Override | ||
public Integer call() throws Exception { // your business logic goes here... | ||
public Integer call() throws Exception { // your business logic // <6> | ||
byte[] fileContents = Files.readAllBytes(file.toPath()); | ||
byte[] digest = MessageDigest.getInstance(algorithm).digest(fileContents); | ||
System.out.printf("%0" + (digest.length*2) + "x%n", new BigInteger(1, digest)); | ||
|
@@ -94,15 +99,11 @@ class CheckSum implements Callable<Integer> { | |
} | ||
---- | ||
|
||
Implement `Runnable` or `Callable`, and your command can be <<Executing Commands,executed>> in one line of code. | ||
The example above uses the `CommandLine.execute` method | ||
to parse the command line, handle errors, handle requests for usage and version help, and invoke the business logic. | ||
Applications can call `System.exit` with the returned exit code to signal success or failure to their caller. | ||
|
||
The <<Mixin Standard Help Options,mixinStandardHelpOptions>> attribute adds `--help` and `--version` options to your application. | ||
_This is how it works_: Create a class ➊ that represents your command and annotate this class with @Command ➑. Let this class implement `Runnable` or `Callable` and picocli will kick off your application after parsing is successfully completed. Then, annotate the fields or methods of the command class with @Parameters ➋ and/or @Option ➌ to declare what positional parameters and/or options your application expects. Picocli will convert the command line arguments given to your app to strongly typed values in the fields ➍ of your class. In the `main` method of your class, use the `CommandLine.execute` method ➎ to parse the command line, handle errors, handle requests for usage and version help, and invoke the business logic ➏. Once your business logic finished, you may call `System.exit` ➐ to return an exit code to your caller, indicating success or failure of your business logic. Additionally, you may make use of the <<Mixin Standard Help Options,mixinStandardHelpOptions>> attribute ➑ which adds `--help` and `--version` options to your application. | ||
|
||
TIP: Picocli also provides a <<Programmatic API,programmatic API>>, separately from the annotations API. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am in two minds about this change. This is useful, but perhaps not at this place in the manual: in the introduction we still want to sell the product. At this stage, readers are not yet convinced that they want to use picocli. I would like casual readers to be able to glance at the example and think to themselves: "that looks easy! I can definitely do that! Wow, that is like a full app in 25 lines of simple code, nice!" 👍 It is true that there is a lot of detail to be explained, but we have the whole rest of the manual to do that... 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I see the point.
O.k. What about leaving the introductory sample as is and moving the 'mini tutorial' to the quick guide (chapter 2.1 Example). We can then place a link in the manual: "For a detailed explanation of the sample application, you may refer to the <<link,quick guide>>.
And additionally, we do have the quick guide ;-) If you agree to that, I'm willing to modify my PR in the sense described above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's a great idea! The Quick Guide is currently just a shorter version of the full manual, but I like the idea of developing it into something that stands on its own more. This would be a nice step in that direction. |
||
|
||
== Getting Started | ||
== Setting up your picocli based project | ||
You can add picocli as an external dependency to your project, or you can include it as source. | ||
|
||
=== Add as External Dependency | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, I am not sure about the changes to the Introduction section.
On the one hand, the additional structure of the Features and Sample Application subsections is nice in that it signals what is coming to readers.
On the other hand, naming the subsection "Features" suggests that what is mentioned in that paragraph are the only features that are noteworthy. Or at least the most important ones. I would like the reader's first impression to be different: "this is just a small taste of what is available".
Many users mention that what they like about picocli is how full-featured it is.
I want to emphasize that in the user manual. That is also why I used Features instead of Table of Contents as the header for the TOC. Strictly speaking, you are correct: this is the Table of Contents. But by labeling it "Features", followed by 200+ entries, the first impression that people get, looking at this document is "wow, this thing has a lot of features". That is what I was aiming for, at least... :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was my intention, and I still consider this an improvement.
I see the point. What about "Selected features", "Features (amongst many others)", "Features that make picocli unique, ...
Accepted. We can revert 'Table of contents' back to 'Features', no problem with that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about Introduction for the section, and Overview for the first subsection (instead of Features)?