summaryrefslogtreecommitdiffstats
path: root/doc/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'doc/index.html')
-rw-r--r--doc/index.html2463
1 files changed, 1838 insertions, 625 deletions
diff --git a/doc/index.html b/doc/index.html
index da0368b..8975316 100644
--- a/doc/index.html
+++ b/doc/index.html
@@ -1,871 +1,2084 @@
-<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
-<html> <head>
+<!DOCTYPE html>
+<html lang="en">
+<head>
+<meta charset="UTF-8">
+<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]-->
+<meta name="viewport" content="width=device-width, initial-scale=1.0">
+<meta name="generator" content="Asciidoctor 1.5.5">
+<meta name="author" content="Cédric Beust">
<title>JCommander</title>
+<style>
+@import url(https://fonts.googleapis.com/css?family=Varela+Round|Open+Sans:400italic,600italic,400,600|Ubuntu+Mono:400);
+/*! normalize.css v2.1.2 | MIT License | git.io/normalize */
+/* ========================================================================== HTML5 display definitions ========================================================================== */
+/** Correct `block` display not defined in IE 8/9. */
+article, aside, details, figcaption, figure, footer, header, hgroup, main, nav, section, summary { display: block; }
-<!--
-<link rel="stylesheet" href="testng.css" type="text/css" />
--->
-
- <link type="text/css" rel="stylesheet" href="http://beust.com/beust.css" />
- <link type="text/css" rel="stylesheet" href="http://jcommander.org/jcommander.css" />
- <script type="text/javascript" src="http://beust.com/prettify.js"></script>
-
- <script type="text/javascript" src="http://beust.com/scripts/shCore.js"></script>
- <script type="text/javascript" src="http://beust.com/scripts/shBrushJava.js"></script>
- <script type="text/javascript" src="http://beust.com/scripts/shBrushXml.js"></script>
- <script type="text/javascript" src="http://beust.com/scripts/shBrushBash.js"></script>
- <script type="text/javascript" src="http://beust.com/scripts/shBrushPlain.js"></script>
- <link type="text/css" rel="stylesheet" href="http://beust.com/styles/shCore.css"/>
- <link type="text/css" rel="stylesheet" href="http://beust.com/styles/shThemeCedric.css"/>
- <script type="text/javascript" src="http://beust.com/toc.js"></script>
- <script type="text/javascript">
- SyntaxHighlighter.config.clipboardSwf = 'scripts/clipboard.swf';
- SyntaxHighlighter.defaults['gutter'] = false;
- SyntaxHighlighter.all();
- </script>
-</head>
+/** Correct `inline-block` display not defined in IE 8/9. */
+audio, canvas, video { display: inline-block; }
-<table width="100%">
- <tr>
- <td align="center">
-<h1>JCommander</h1>
-<h2>Because life is too short to parse command line parameters</h2>
-<h3>
- <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
- <input type="hidden" name="cmd" value="_donations">
- <input type="hidden" name="business" value="cedric@beust.com">
- <input type="hidden" name="lc" value="US">
- <input type="hidden" name="item_name" value="Cedric Beust">
- <input type="hidden" name="no_note" value="0">
- <input type="hidden" name="currency_code" value="USD">
- <input type="hidden" name="bn" value="PP-DonationsBF:btn_donate_LG.gif:NonHostedGuest">
- <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
- <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
- </form>
-</h3>
- </td>
- </tr>
- <tr>
- <td align="right">
- Created: July 13th, 2010
- </td>
- </tr>
- <tr>
- <td align="right">
- Last updated: January 14th, 2015
- </td>
- </tr>
- <tr><td align="right"><a href="mailto:cedric@beust.com">C&eacute;dric Beust</a></td></tr>
-</table>
+/** Prevent modern browsers from displaying `audio` without controls. Remove excess height in iOS 5 devices. */
+audio:not([controls]) { display: none; height: 0; }
-<h2>Table of contents</h2>
-<div id="table-of-contents">
-</div>
+/** Address `[hidden]` styling not present in IE 8/9. Hide the `template` element in IE, Safari, and Firefox < 22. */
+[hidden], template { display: none; }
+script { display: none !important; }
+/* ========================================================================== Base ========================================================================== */
+/** 1. Set default font family to sans-serif. 2. Prevent iOS text size adjust after orientation change, without disabling user zoom. */
+html { font-family: sans-serif; /* 1 */ -ms-text-size-adjust: 100%; /* 2 */ -webkit-text-size-adjust: 100%; /* 2 */ }
-<h2><a class="section" name="Overview">Overview</a></h2>
+/** Remove default margin. */
+body { margin: 0; }
-JCommander is a very small Java framework that makes it trivial to parse command line parameters.
-<p>
-You annotate fields with descriptions of your options:
+/* ========================================================================== Links ========================================================================== */
+/** Remove the gray background color from active links in IE 10. */
+a { background: transparent; }
-<pre class="brush: java">
-import com.beust.jcommander.Parameter;
+/** Address `outline` inconsistency between Chrome and other browsers. */
+a:focus { outline: thin dotted; }
-public class JCommanderExample {
- @Parameter
- private List&lt;String&gt; parameters = new ArrayList&lt;String&gt;();
+/** Improve readability when focused and also mouse hovered in all browsers. */
+a:active, a:hover { outline: 0; }
- @Parameter(names = { "-log", "-verbose" }, description = "Level of verbosity")
- private Integer verbose = 1;
+/* ========================================================================== Typography ========================================================================== */
+/** Address variable `h1` font-size and margin within `section` and `article` contexts in Firefox 4+, Safari 5, and Chrome. */
+h1 { font-size: 2em; margin: 0.67em 0; }
- @Parameter(names = "-groups", description = "Comma-separated list of group names to be run")
- private String groups;
+/** Address styling not present in IE 8/9, Safari 5, and Chrome. */
+abbr[title] { border-bottom: 1px dotted; }
- @Parameter(names = "-debug", description = "Debug mode")
- private boolean debug = false;
-}
-</pre>
+/** Address style set to `bolder` in Firefox 4+, Safari 5, and Chrome. */
+b, strong { font-weight: bold; }
-and then you simply ask JCommander to parse:
+/** Address styling not present in Safari 5 and Chrome. */
+dfn { font-style: italic; }
-<pre class="brush: java">
-JCommanderExample jct = new JCommanderExample();
-String[] argv = { "-log", "2", "-groups", "unit" };
-new JCommander(jct, argv);
+/** Address differences between Firefox and other browsers. */
+hr { -moz-box-sizing: content-box; box-sizing: content-box; height: 0; }
-Assert.assertEquals(jct.verbose.intValue(), 2);
-</pre>
+/** Address styling not present in IE 8/9. */
+mark { background: #ff0; color: #000; }
-<h2><a class="section" name="Types_of_options">Types of options</a></h2>
+/** Correct font family set oddly in Safari 5 and Chrome. */
+code, kbd, pre, samp { font-family: monospace, serif; font-size: 1em; }
-The fields representing your parameters can be of any type. Basic types (<tt>Integer</tt>, <tt>Boolean</tt/>., etc...) are supported by default and you can write type converters to support any other type (<tt>File</tt>, etc...).
+/** Improve readability of pre-formatted text in all browsers. */
+pre { white-space: pre-wrap; }
-<h4>Boolean</h4>
+/** Set consistent quote types. */
+q { quotes: "\201C" "\201D" "\2018" "\2019"; }
-When a <tt>Parameter</tt> annotation is found on a field of type <tt>boolean</tt> or <tt>Boolean</tt>, JCommander interprets it as an option with an <em>arity</em> of 0:
+/** Address inconsistent and variable font size in all browsers. */
+small { font-size: 80%; }
-<pre class="brush: java">
-@Parameter(names = "-debug", description = "Debug mode")
-private boolean debug = false;
-</pre>
+/** Prevent `sub` and `sup` affecting `line-height` in all browsers. */
+sub, sup { font-size: 75%; line-height: 0; position: relative; vertical-align: baseline; }
-Such a parameter does not require any additional parameter on the command line and if it's detected during parsing, the corresponding field will be set to <tt>true</tt>.
+sup { top: -0.5em; }
-<p>
+sub { bottom: -0.25em; }
- If you want to define a boolean parameter that's <tt>true</tt> by default, you can declare it as having an arity of 1. Users will then have to specify the value they want explicitly:
+/* ========================================================================== Embedded content ========================================================================== */
+/** Remove border when inside `a` element in IE 8/9. */
+img { border: 0; }
- <pre class="brush: java">
- @Parameter(names = "-debug", description = "Debug mode", arity = 1)
- private boolean debug = true;
- </pre>
+/** Correct overflow displayed oddly in IE 9. */
+svg:not(:root) { overflow: hidden; }
- Invoke with either of:
+/* ========================================================================== Figures ========================================================================== */
+/** Address margin not present in IE 8/9 and Safari 5. */
+figure { margin: 0; }
- <pre class="brush: plain">
- program -debug true
- program -debug false
- </pre>
+/* ========================================================================== Forms ========================================================================== */
+/** Define consistent border, margin, and padding. */
+fieldset { border: 1px solid #c0c0c0; margin: 0 2px; padding: 0.35em 0.625em 0.75em; }
-<h4>String, Integer, Long</h4>
+/** 1. Correct `color` not being inherited in IE 8/9. 2. Remove padding so people aren't caught out if they zero out fieldsets. */
+legend { border: 0; /* 1 */ padding: 0; /* 2 */ }
-When a <tt>Parameter</tt> annotation is found on a field of type <tt>String</tt>, <tt>Integer</tt>, <tt>int</tt>, <tt>Long</tt> or <tt>long</tt>, JCommander will parse the following parameter and it will attempt to cast it to the right type:
+/** 1. Correct font family not being inherited in all browsers. 2. Correct font size not being inherited in all browsers. 3. Address margins set differently in Firefox 4+, Safari 5, and Chrome. */
+button, input, select, textarea { font-family: inherit; /* 1 */ font-size: 100%; /* 2 */ margin: 0; /* 3 */ }
-<pre class="brush: java">
-@Parameter(names = "-log", description = "Level of verbosity")
-private Integer verbose = 1;
-</pre>
+/** Address Firefox 4+ setting `line-height` on `input` using `!important` in the UA stylesheet. */
+button, input { line-height: normal; }
-<pre class="brush: plain">
-java Main -log 3
-</pre>
+/** Address inconsistent `text-transform` inheritance for `button` and `select`. All other form control elements do not inherit `text-transform` values. Correct `button` style inheritance in Chrome, Safari 5+, and IE 8+. Correct `select` style inheritance in Firefox 4+ and Opera. */
+button, select { text-transform: none; }
-will cause the field <tt>verbose</tt> to receive the value 3, however:
+/** 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio` and `video` controls. 2. Correct inability to style clickable `input` types in iOS. 3. Improve usability and consistency of cursor style between image-type `input` and others. */
+button, html input[type="button"], input[type="reset"], input[type="submit"] { -webkit-appearance: button; /* 2 */ cursor: pointer; /* 3 */ }
-<pre class="brush: plain">
-java Main -log test
-</pre>
+/** Re-set default cursor for disabled elements. */
+button[disabled], html input[disabled] { cursor: default; }
-will cause an exception to be thrown.
+/** 1. Address box sizing set to `content-box` in IE 8/9. 2. Remove excess padding in IE 8/9. */
+input[type="checkbox"], input[type="radio"] { box-sizing: border-box; /* 1 */ padding: 0; /* 2 */ }
-<h4>Lists</h4>
+/** 1. Address `appearance` set to `searchfield` in Safari 5 and Chrome. 2. Address `box-sizing` set to `border-box` in Safari 5 and Chrome (include `-moz` to future-proof). */
+input[type="search"] { -webkit-appearance: textfield; /* 1 */ -moz-box-sizing: content-box; -webkit-box-sizing: content-box; /* 2 */ box-sizing: content-box; }
-When a <tt>Parameter</tt> annotation is found on a field of type <tt>List</tt>, JCommander will interpret it as an option that can occur multiple times:
+/** Remove inner padding and search cancel button in Safari 5 and Chrome on OS X. */
+input[type="search"]::-webkit-search-cancel-button, input[type="search"]::-webkit-search-decoration { -webkit-appearance: none; }
-<pre class="brush: java">
-@Parameter(names = "-host", description = "The host")
-private List&lt;String&gt; hosts = new ArrayList&lt;String&gt;();
-</pre>
+/** Remove inner padding and border in Firefox 4+. */
+button::-moz-focus-inner, input::-moz-focus-inner { border: 0; padding: 0; }
-will allow you to parse the following command line:
+/** 1. Remove default vertical scrollbar in IE 8/9. 2. Improve readability and alignment in all browsers. */
+textarea { overflow: auto; /* 1 */ vertical-align: top; /* 2 */ }
-<pre class="brush: plain">
-java Main -host host1 -verbose -host host2
-</pre>
+/* ========================================================================== Tables ========================================================================== */
+/** Remove most spacing between table cells. */
+table { border-collapse: collapse; border-spacing: 0; }
-When JCommander is done parsing the line above, the field <tt>hosts</tt> will contain the strings "host1" and "host2".
+meta.foundation-mq-small { font-family: "only screen and (min-width: 768px)"; width: 768px; }
-<h4>Password</h4>
+meta.foundation-mq-medium { font-family: "only screen and (min-width:1280px)"; width: 1280px; }
-If one of your parameters is a password or some other value that you do not wish to appear in your history or in clear, you can declare it of type <tt>password</tt> and JCommander will then ask you to enter it in the console:
+meta.foundation-mq-large { font-family: "only screen and (min-width:1440px)"; width: 1440px; }
-<pre class="brush: java">
-public class ArgsPassword {
- @Parameter(names = "-password", description = "Connection password", password = true)
- private String password;
-}
-</pre>
+*, *:before, *:after { -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; }
-When you run your program, you will get the following prompt:
+html, body { font-size: 100%; }
-<pre class="brush: plain">
-Value for -password (Connection password):
-</pre>
+body { background: #fefdfd; color: rgba(0, 0, 0, 0.8); padding: 0; margin: 0; font-family: "Open Sans", sans-serif; font-weight: normal; font-style: normal; line-height: 1; position: relative; cursor: auto; }
-You will need to type the value at this point before JCommander resumes.
+a:hover { cursor: pointer; }
-<h4>Echo Input</h4>
+img, object, embed { max-width: 100%; height: auto; }
-In Java 6, by default, you will not be able to see what you type for passwords entered at the prompt (Java 5 and lower will always show the password). However, you can override this by setting <tt>echoInput</tt> to "true" (default is "false" and this setting only has an effect when <tt>password</tt> is "true"):
-<pre class="brush: java">
-public class ArgsPassword {
- @Parameter(names = "-password", description = "Connection password", password = true, echoInput = true)
- private String password;
-}
-</pre>
+object, embed { height: 100%; }
-<h2><a class="section" name="Custom_types">Custom types</a></h2>
+img { -ms-interpolation-mode: bicubic; }
-<h3>By annotation</h3>
+#map_canvas img, #map_canvas embed, #map_canvas object, .map_canvas img, .map_canvas embed, .map_canvas object { max-width: none !important; }
-By default, JCommander parses the command line into basic types only (strings, booleans, integers and longs). Very often, your application actually needs more complex types, such as files, host names, lists, etc... To achieve this, you can write a type converter by implementing the following interface:
+.left { float: left !important; }
-<pre class="brush: java">
-public interface IStringConverter&lt;T&gt; {
- T convert(String value);
-}
-</pre>
+.right { float: right !important; }
-For example, here is a converter that turns a string into a <tt>File</tt>:
+.text-left { text-align: left !important; }
-<pre class="brush: java">
-public class FileConverter implements IStringConverter&lt;File&gt; {
- @Override
- public File convert(String value) {
- return new File(value);
- }
-}
-</pre>
+.text-right { text-align: right !important; }
-Then, all you need to do is declare your field with the correct type and specify the converter as an attribute:
+.text-center { text-align: center !important; }
-<pre class="brush: java">
-@Parameter(names = "-file", converter = FileConverter.class)
-File file;
-</pre>
+.text-justify { text-align: justify !important; }
-JCommander ships with a few common converters (e.g. one that turns a comma separated list into a <tt>List&lt;String&gt;)</tt>.
+.hide { display: none; }
-<h3>By factory</h3>
+.antialiased { -webkit-font-smoothing: antialiased; }
-If the custom types you use appear multiple times in your application, having to specify the converter in each annotation can become tedious. To address this, you can use an <tt>IStringConverterFactory</tt>:
+img { display: inline-block; vertical-align: middle; }
-<pre class="brush: java">
-public interface IStringConverterFactory {
- &lt;T&gt; Class&lt;? extends IStringConverter&lt;T&gt;&gt; getConverter(Class&lt;T&gt; forType);
-}
-</pre>
+textarea { height: auto; min-height: 50px; }
-For example, suppose you need to parse a string representing a host and a port:
+select { width: 100%; }
-<pre class="brush: plain">
-java App -target example.com:8080
-</pre>
+object, svg { display: inline-block; vertical-align: middle; }
-You define the holder class :
+.center { margin-left: auto; margin-right: auto; }
-<pre class="brush: java">
-public class HostPort {
- private String host;
- private Integer port;
-}
-</pre>
+.spread { width: 100%; }
-and the string converter to create instances of this class:
+p.lead, .paragraph.lead > p, #preamble > .sectionbody > .paragraph:first-of-type p { font-size: 1.21875em; line-height: 1.6; }
-<pre class="brush: java">
-class HostPortConverter implements IStringConverter&lt;HostPort&gt; {
- @Override
- public HostPort convert(String value) {
- HostPort result = new HostPort();
- String[] s = value.split(":");
- result.host = s[0];
- result.port = Integer.parseInt(s[1]);
+.subheader, .admonitionblock td.content > .title, .audioblock > .title, .exampleblock > .title, .imageblock > .title, .listingblock > .title, .literalblock > .title, .stemblock > .title, .openblock > .title, .paragraph > .title, .quoteblock > .title, table.tableblock > .title, .verseblock > .title, .videoblock > .title, .dlist > .title, .olist > .title, .ulist > .title, .qlist > .title, .hdlist > .title { line-height: 1.25; color: #002c5e; font-weight: 300; margin-top: 0.2em; margin-bottom: 0.5em; }
- return result;
- }
-}
-</pre>
+/* Typography resets */
+div, dl, dt, dd, ul, ol, li, h1, h2, h3, #toctitle, .sidebarblock > .content > .title, h4, h5, h6, pre, form, p, blockquote, th, td { margin: 0; padding: 0; direction: ltr; }
-The factory is straightforward:
+/* Default Link Styles */
+a { color: #005580; text-decoration: underline; line-height: inherit; }
+a:hover, a:focus { color: #078d71; }
+a img { border: none; }
-<pre class="brush: java">
-public class Factory implements IStringConverterFactory {
- public Class&lt;? extends IStringConverter&lt;?&gt;&gt; getConverter(Class forType) {
- if (forType.equals(HostPort.class)) return HostPortConverter.class;
- else return null;
- }
-</pre>
+/* Default paragraph styles */
+p { font-family: inherit; font-weight: normal; font-size: 1em; line-height: 1.5; margin-bottom: 1.25em; text-rendering: optimizeLegibility; }
+p aside { font-size: 0.875em; line-height: 1.35; font-style: italic; }
-You can now use the type <tt>HostPort</tt> as a parameter without any <tt>converterClass</tt> attribute:
+/* Default header styles */
+h1, h2, h3, #toctitle, .sidebarblock > .content > .title, h4, h5, h6 { font-family: "Varela Round", sans-serif; font-weight: 400; font-style: normal; color: #00326b; text-rendering: optimizeLegibility; margin-top: 0.8em; margin-bottom: 0.5em; line-height: 1.0625em; }
+h1 small, h2 small, h3 small, #toctitle small, .sidebarblock > .content > .title small, h4 small, h5 small, h6 small { font-size: 60%; color: #057aff; line-height: 0; }
-<pre class="brush: java">
-public class ArgsConverterFactory {
- @Parameter(names = "-hostport")
- private HostPort hostPort;
-}
-</pre>
+h1 { font-size: 2.125em; }
+h2 { font-size: 1.6875em; }
-All you need to do is add the factory to your JCommander object:
+h3, #toctitle, .sidebarblock > .content > .title { font-size: 1.375em; }
-<pre class="brush: java">
- ArgsConverterFactory a = new ArgsConverterFactory();
- JCommander jc = new JCommander(a);
- jc.addConverterFactory(new Factory());
- jc.parse("-hostport", "example.com:8080");
+h4 { font-size: 1.125em; }
- Assert.assertEquals(a.hostPort.host, "example.com");
- Assert.assertEquals(a.hostPort.port.intValue(), 8080);
-</pre>
+h5 { font-size: 1.125em; }
+h6 { font-size: 1em; }
-Another advantage of using string converter factories is that your factories can come from a dependency injection framework.
+hr { border: solid rgba(145, 135, 84, 0.15); border-width: 1px 0 0; clear: both; margin: 1.25em 0 1.1875em; height: 0; }
-<h2><a class="section" name="Parameter_validation">Parameter validation</a></h2>
+/* Helpful Typography Defaults */
+em, i { font-style: italic; line-height: inherit; }
-You can ask JCommander to perform early validation on your parameters by providing a class that implements the following interface:
+strong, b { font-weight: bold; line-height: inherit; }
-<pre class="brush:java">
-public interface IParameterValidator {
- /**
- * Validate the parameter.
- *
- * @param name The name of the parameter (e.g. "-host").
- * @param value The value of the parameter that we need to validate
- *
- * @throws ParameterException Thrown if the value of the parameter is invalid.
- */
- void validate(String name, String value) throws ParameterException;
-}
+small { font-size: 60%; line-height: inherit; }
-</pre>
+code { font-family: "Ubuntu Mono", "Inconsolata", monospace; font-weight: 400; color: #331d00; }
-Here is an example implementation that will make sure that the parameter is a positive integer:
+/* Lists */
+ul, ol, dl { font-size: 1em; line-height: 1.5; margin-bottom: 1.25em; list-style-position: outside; font-family: inherit; }
-<pre class="brush:java">
-public class PositiveInteger implements IParameterValidator {
- public void validate(String name, String value)
- throws ParameterException {
- int n = Integer.parseInt(value);
- if (n < 0) {
- throw new ParameterException("Parameter " + name + " should be positive (found " + value +")");
- }
- }
-}
-</pre>
+ul, ol { margin-left: 1.5em; }
+ul.no-bullet, ol.no-bullet { margin-left: 1.5em; }
-Specify the name of a class implementing this interface in the <tt>validateWith</tt> attribute of your <tt>@Parameter</tt> annotations:
+/* Unordered Lists */
+ul li ul, ul li ol { margin-left: 1.25em; margin-bottom: 0; font-size: 1em; /* Override nested font-size change */ }
+ul.square li ul, ul.circle li ul, ul.disc li ul { list-style: inherit; }
+ul.square { list-style-type: square; }
+ul.circle { list-style-type: circle; }
+ul.disc { list-style-type: disc; }
+ul.no-bullet { list-style: none; }
-<pre class="brush:java">
-@Parameter(names = "-age", validateWith = PositiveInteger.class)
-private Integer age;
-</pre>
+/* Ordered Lists */
+ol li ul, ol li ol { margin-left: 1.25em; margin-bottom: 0; }
-Attempting to pass a negative integer to this option will cause a <tt>ParameterException</tt> to be thrown.
+/* Definition Lists */
+dl dt { margin-bottom: 0.3125em; font-weight: bold; }
+dl dd { margin-bottom: 1.25em; }
+/* Abbreviations */
+abbr, acronym { text-transform: uppercase; font-size: 90%; color: rgba(0, 0, 0, 0.8); border-bottom: 1px dotted #dddddd; cursor: help; }
-<h2><a class="section" name="Main_parameter">Main parameter</a></h2>
-So far, all the <tt>@Parameter</tt> annotations we have seen had defined an attribute called <tt>names</tt>. You can define one (and at most one) parameter without any such attribute. This parameter needs to be a <tt>List&lt;String&gt;</tt> and it will contain all the parameters that are not options:
+abbr { text-transform: none; }
-<pre class="brush: java">
-@Parameter(description = "Files")
-private List&lt;String&gt; files = new ArrayList&lt;String&gt;();
+/* Blockquotes */
+blockquote { margin: 0 0 1.25em; padding: 0.5625em 1.25em 0 1.1875em; border-left: 1px solid #dddddd; }
+blockquote cite { display: block; font-size: 0.8125em; color: #666666; }
+blockquote cite:before { content: "\2014 \0020"; }
+blockquote cite a, blockquote cite a:visited { color: #666666; }
-@Parameter(names = "-debug", description = "Debugging level")
-private Integer debug = 1;
-</pre>
+blockquote, blockquote p { line-height: 1.5; color: #999999; }
-will allow you to parse:
+/* Microformats */
+.vcard { display: inline-block; margin: 0 0 1.25em 0; border: 1px solid #dddddd; padding: 0.625em 0.75em; }
+.vcard li { margin: 0; display: block; }
+.vcard .fn { font-weight: bold; font-size: 0.9375em; }
-<pre class="brush: plain">
-java Main -debug file1 file2
-</pre>
+.vevent .summary { font-weight: bold; }
+.vevent abbr { cursor: auto; text-decoration: none; font-weight: bold; border: none; padding: 0 0.0625em; }
-and the field <tt>files</tt> will receive the strings "file1" and "file2".
+@media only screen and (min-width: 768px) { h1, h2, h3, #toctitle, .sidebarblock > .content > .title, h4, h5, h6 { line-height: 1.25; }
+ h1 { font-size: 2.75em; }
+ h2 { font-size: 2.3125em; }
+ h3, #toctitle, .sidebarblock > .content > .title { font-size: 1.6875em; }
+ h4 { font-size: 1.4375em; } }
+/* Tables */
+table { background: white; margin-bottom: 1.25em; border: solid 1px rgba(145, 135, 84, 0.15); }
+table thead, table tfoot { background: rgba(119, 84, 22, 0.1); font-weight: bold; }
+table thead tr th, table thead tr td, table tfoot tr th, table tfoot tr td { padding: 0.5em 0.625em 0.625em; font-size: inherit; color: rgba(0, 0, 0, 0.8); text-align: left; }
+table tr th, table tr td { padding: 0.5625em 0.625em; font-size: inherit; color: rgba(0, 0, 0, 0.8); }
+table tr.even, table tr.alt, table tr:nth-of-type(even) { background: rgba(119, 84, 22, 0.025); }
+table thead tr th, table tfoot tr th, table tbody tr td, table tr td, table tfoot tr td { display: table-cell; line-height: 1.5; }
-<h2><a class="section" name="Private_parameters">Private parameters</a></h2>
+body { -moz-osx-font-smoothing: grayscale; -webkit-font-smoothing: antialiased; tab-size: 4; }
-Parameters can be private:
+h1, h2, h3, #toctitle, .sidebarblock > .content > .title, h4, h5, h6 { line-height: 1.25; }
-<pre class="brush: java">
-public class ArgsPrivate {
- @Parameter(names = "-verbose")
- private Integer verbose = 1;
+.clearfix:before, .clearfix:after, .float-group:before, .float-group:after { content: " "; display: table; }
+.clearfix:after, .float-group:after { clear: both; }
- public Integer getVerbose() {
- return verbose;
- }
-}
-</pre>
+*:not(pre) > code { font-size: 1.0625em; font-style: normal !important; letter-spacing: 0; padding: 0; line-height: 1.25; word-wrap: break-word; }
+*:not(pre) > code.nobreak { word-wrap: normal; }
+*:not(pre) > code.nowrap { white-space: nowrap; }
-<pre class="brush: java">
-ArgsPrivate args = new ArgsPrivate();
-new JCommander(args, "-verbose", "3");
-Assert.assertEquals(args.getVerbose().intValue(), 3);
-</pre>
+pre, pre > code { line-height: 1.4; color: inherit; font-family: "Liberation Mono", "Consolas", monospace; font-weight: normal; }
-<h2><a class="section" name="Separators">Parameter separators</a></h2>
+em em { font-style: normal; }
-By default, parameters are separated by spaces, but you can change this setting to allow different separators:
+strong strong { font-weight: normal; }
-<pre class="brush: plain">
-java Main -log:3
-</pre>
+.keyseq { color: rgba(51, 51, 51, 0.8); }
-or
+kbd { font-family: "Ubuntu Mono", "Inconsolata", monospace; display: inline-block; color: rgba(0, 0, 0, 0.8); font-size: 0.65em; line-height: 1.45; background-color: #f7f7f7; border: 1px solid #ccc; -webkit-border-radius: 3px; border-radius: 3px; -webkit-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 0 0 0.1em white inset; box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 0 0 0.1em white inset; margin: 0 0.15em; padding: 0.2em 0.5em; vertical-align: middle; position: relative; top: -0.1em; white-space: nowrap; }
-<pre class="brush: plain">
-java Main -level=42
-</pre>
+.keyseq kbd:first-child { margin-left: 0; }
-You define the separator with the <tt>@Parameters</tt> annotation:
+.keyseq kbd:last-child { margin-right: 0; }
-<pre class="brush: java">
-@Parameters(separators = "=")
-public class SeparatorEqual {
- @Parameter(names = "-level")
- private Integer level = 2;
-}
-</pre>
+.menuseq, .menu { color: rgba(0, 0, 0, 0.8); }
+b.button:before, b.button:after { position: relative; top: -1px; font-weight: normal; }
+b.button:before { content: "["; padding: 0 3px 0 2px; }
+b.button:after { content: "]"; padding: 0 2px 0 3px; }
+p a > code:hover { color: #1a0f00; }
-<h2><a class="section" name="Multiple_descriptions">Multiple descriptions</a></h2>
+#header, #content, #footnotes, #footer { width: 100%; margin-left: auto; margin-right: auto; margin-top: 0; margin-bottom: 0; max-width: 62.5em; *zoom: 1; position: relative; padding-left: 0.9375em; padding-right: 0.9375em; }
+#header:before, #header:after, #content:before, #content:after, #footnotes:before, #footnotes:after, #footer:before, #footer:after { content: " "; display: table; }
+#header:after, #content:after, #footnotes:after, #footer:after { clear: both; }
-You can spread the description of your parameters on more than one
-class. For example, you can define the following two classes:
+#content { margin-top: 1.25em; }
-<p>
+#content:before { content: none; }
-<h3 class="sourcetitle">ArgsMaster.java</h3>
-<pre class="brush: java">
-public class ArgsMaster {
- @Parameter(names = "-master")
- private String master;
-}
-</pre>
+#header > h1:first-child { color: #703f1c; margin-top: 2.25rem; margin-bottom: 0; }
+#header > h1:first-child + #toc { margin-top: 8px; border-top: 1px solid rgba(145, 135, 84, 0.15); }
+#header > h1:only-child, body.toc2 #header > h1:nth-last-child(2) { border-bottom: 1px solid rgba(145, 135, 84, 0.15); padding-bottom: 8px; }
+#header .details { border-bottom: 1px solid rgba(145, 135, 84, 0.15); line-height: 1.45; padding-top: 0.25em; padding-bottom: 0.25em; padding-left: 0.25em; color: #666666; display: -ms-flexbox; display: -webkit-flex; display: flex; -ms-flex-flow: row wrap; -webkit-flex-flow: row wrap; flex-flow: row wrap; }
+#header .details span:first-child { margin-left: -0.125em; }
+#header .details span.email a { color: #999999; }
+#header .details br { display: none; }
+#header .details br + span:before { content: "\00a0\2013\00a0"; }
+#header .details br + span.author:before { content: "\00a0\22c5\00a0"; color: #999999; }
+#header .details br + span#revremark:before { content: "\00a0|\00a0"; }
+#header #revnumber { text-transform: capitalize; }
+#header #revnumber:after { content: "\00a0"; }
-<h3 class="sourcetitle">ArgsSlave.java</h3>
-<pre class="brush: java">
-public class ArgsSlave {
- @Parameter(names = "-slave")
- private String slave;
-}
-</pre>
+#content > h1:first-child:not([class]) { color: #703f1c; border-bottom: 1px solid rgba(145, 135, 84, 0.15); padding-bottom: 8px; margin-top: 0; padding-top: 1rem; margin-bottom: 1.25rem; }
-and pass these two objects to JCommander:
+#toc { border-bottom: 0px solid #dddddd; padding-bottom: 0.5em; }
+#toc > ul { margin-left: 0.125em; }
+#toc ul.sectlevel0 > li > a { font-style: italic; }
+#toc ul.sectlevel0 ul.sectlevel1 { margin: 0.5em 0; }
+#toc ul { font-family: "Varela Round", sans-serif; list-style-type: none; }
+#toc li { line-height: 1.3334; margin-top: 0.3334em; }
+#toc a { text-decoration: none; }
+#toc a:active { text-decoration: underline; }
-<pre class="brush: java">
-ArgsMaster m = new ArgsMaster();
-ArgsSlave s = new ArgsSlave();
-String[] argv = { "-master", "master", "-slave", "slave" };
-new JCommander(new Object[] { m , s }, argv);
+#toctitle { color: #002c5e; font-size: 1.2em; }
-Assert.assertEquals(m.master, "master");
-Assert.assertEquals(s.slave, "slave");
-</pre>
+@media only screen and (min-width: 768px) { #toctitle { font-size: 1.375em; }
+ body.toc2 { padding-left: 15em; padding-right: 0; }
+ #toc.toc2 { margin-top: 0 !important; background-color: #f2f2f4; position: fixed; width: 15em; left: 0; top: 0; border-right: 1px solid #dddddd; border-top-width: 0 !important; border-bottom-width: 0 !important; z-index: 1000; padding: 1.25em 1em; height: 100%; overflow: auto; }
+ #toc.toc2 #toctitle { margin-top: 0; margin-bottom: 0.8rem; font-size: 1.2em; }
+ #toc.toc2 > ul { font-size: 0.9em; margin-bottom: 0; }
+ #toc.toc2 ul ul { margin-left: 0; padding-left: 1em; }
+ #toc.toc2 ul.sectlevel0 ul.sectlevel1 { padding-left: 0; margin-top: 0.5em; margin-bottom: 0.5em; }
+ body.toc2.toc-right { padding-left: 0; padding-right: 15em; }
+ body.toc2.toc-right #toc.toc2 { border-right-width: 0; border-left: 1px solid #dddddd; left: auto; right: 0; } }
+@media only screen and (min-width: 1280px) { body.toc2 { padding-left: 20em; padding-right: 0; }
+ #toc.toc2 { width: 20em; }
+ #toc.toc2 #toctitle { font-size: 1.375em; }
+ #toc.toc2 > ul { font-size: 0.95em; }
+ #toc.toc2 ul ul { padding-left: 1.25em; }
+ body.toc2.toc-right { padding-left: 0; padding-right: 20em; } }
+#content #toc { border-style: solid; border-width: 1px; border-color: #d6d6dd; margin-bottom: 1.25em; padding: 1.25em; background: #f2f2f4; -webkit-border-radius: 6px; border-radius: 6px; }
+#content #toc > :first-child { margin-top: 0; }
+#content #toc > :last-child { margin-bottom: 0; }
+#footer { max-width: 100%; background-color: #0b445a; padding: 1.25em; }
-<h2><a class="section" name="Syntax">@ syntax</a></h2>
+#footer-text { color: #fefdfd; line-height: 1.35; }
-JCommander supports the @ syntax, which allows you to put all your options into a file and pass this file as parameter:
+.sect1 { padding-bottom: 0.625em; }
-<p>
+@media only screen and (min-width: 768px) { .sect1 { padding-bottom: 1.25em; } }
+.sect1 + .sect1 { border-top: 0px solid #dddddd; }
-<div class="sourcetitle">/tmp/parameters</div>
-<pre class="brush: plain">
--verbose
-file1
-file2
-file3
-</pre>
-<pre class="brush: plain">
-java Main @/tmp/parameters
-</pre>
+#content h1 > a.anchor, h2 > a.anchor, h3 > a.anchor, #toctitle > a.anchor, .sidebarblock > .content > .title > a.anchor, h4 > a.anchor, h5 > a.anchor, h6 > a.anchor { position: absolute; z-index: 1001; width: 1.5ex; margin-left: -1.5ex; display: block; text-decoration: none !important; visibility: hidden; text-align: center; font-weight: normal; }
+#content h1 > a.anchor:before, h2 > a.anchor:before, h3 > a.anchor:before, #toctitle > a.anchor:before, .sidebarblock > .content > .title > a.anchor:before, h4 > a.anchor:before, h5 > a.anchor:before, h6 > a.anchor:before { content: "\00A7"; font-size: 0.85em; display: block; padding-top: 0.1em; }
+#content h1:hover > a.anchor, #content h1 > a.anchor:hover, h2:hover > a.anchor, h2 > a.anchor:hover, h3:hover > a.anchor, #toctitle:hover > a.anchor, .sidebarblock > .content > .title:hover > a.anchor, h3 > a.anchor:hover, #toctitle > a.anchor:hover, .sidebarblock > .content > .title > a.anchor:hover, h4:hover > a.anchor, h4 > a.anchor:hover, h5:hover > a.anchor, h5 > a.anchor:hover, h6:hover > a.anchor, h6 > a.anchor:hover { visibility: visible; }
+#content h1 > a.link, h2 > a.link, h3 > a.link, #toctitle > a.link, .sidebarblock > .content > .title > a.link, h4 > a.link, h5 > a.link, h6 > a.link { color: #00326b; text-decoration: none; }
+#content h1 > a.link:hover, h2 > a.link:hover, h3 > a.link:hover, #toctitle > a.link:hover, .sidebarblock > .content > .title > a.link:hover, h4 > a.link:hover, h5 > a.link:hover, h6 > a.link:hover { color: #002652; }
-<h2><a class="section" name="Arities">Arities (multiple values for parameters)</a></h2>
+.audioblock, .imageblock, .literalblock, .listingblock, .stemblock, .videoblock { margin-bottom: 1.25em; }
-<h3><a class="section" name="fixed-arities" indent="..">Fixed arities</a></h3>
+.admonitionblock td.content > .title, .audioblock > .title, .exampleblock > .title, .imageblock > .title, .listingblock > .title, .literalblock > .title, .stemblock > .title, .openblock > .title, .paragraph > .title, .quoteblock > .title, table.tableblock > .title, .verseblock > .title, .videoblock > .title, .dlist > .title, .olist > .title, .ulist > .title, .qlist > .title, .hdlist > .title { text-rendering: optimizeLegibility; text-align: left; }
-If some of your parameters require more than one value, such as the
-following example where two values are expected after <tt>-pairs</tt>:
+table.tableblock > caption.title { white-space: nowrap; overflow: visible; max-width: 0; }
-<pre class="brush: plain">
-java Main -pairs slave master foo.xml
-</pre>
+.paragraph.lead > p, #preamble > .sectionbody > .paragraph:first-of-type p { color: #703f1c; }
-then you need to define your parameter with the <tt>arity</tt>
-attribute and make that parameter a <tt>List&lt;String&gt;</tt>:
+table.tableblock #preamble > .sectionbody > .paragraph:first-of-type p { font-size: inherit; }
-<pre class="brush: java">
-@Parameter(names = "-pairs", arity = 2, description = "Pairs")
-private List&lt;String&gt; pairs;
-</pre>
+.admonitionblock > table { border-collapse: separate; border: 0; background: none; width: 100%; }
+.admonitionblock > table td.icon { text-align: center; width: 80px; }
+.admonitionblock > table td.icon img { max-width: initial; }
+.admonitionblock > table td.icon .title { font-weight: bold; font-family: "Varela Round", sans-serif; text-transform: uppercase; }
+.admonitionblock > table td.content { padding-left: 1.125em; padding-right: 1.25em; border-left: 1px solid rgba(145, 135, 84, 0.15); color: #666666; }
+.admonitionblock > table td.content > :last-child > :last-child { margin-bottom: 0; }
-You don't need to specify an arity for parameters of type
-<tt>boolean</tt> or <tt>Boolean</tt> (which have a default arity of 0)
-and of types <tt>String</tt>, <tt>Integer</tt>, <tt>int</tt>,
-<tt>Long</tt> and <tt>long</tt> (which have a default arity of 1).
+.exampleblock > .content { border-style: solid; border-width: 1px; border-color: #eddbdb; margin-bottom: 1.25em; padding: 1.25em; background: #fefdfd; -webkit-border-radius: 6px; border-radius: 6px; }
+.exampleblock > .content > :first-child { margin-top: 0; }
+.exampleblock > .content > :last-child { margin-bottom: 0; }
-<p>
-Also, note that only <tt>List&lt;String&gt;</tt> is allowed for
-parameters that define an arity. You will have to convert these values
-yourself if the parameters you need are of type <tt>Integer</tt> or
-other (this limitation is due to Java's erasure).
+.sidebarblock { border-style: solid; border-width: 1px; border-color: #d6d6dd; margin-bottom: 1.25em; padding: 1.25em; background: #f2f2f4; -webkit-border-radius: 6px; border-radius: 6px; }
+.sidebarblock > :first-child { margin-top: 0; }
+.sidebarblock > :last-child { margin-bottom: 0; }
+.sidebarblock > .content > .title { color: #002c5e; margin-top: 0; }
-<h3><a class="section" name="variable-arities" indent="..">Variable arities</a></h3>
+.exampleblock > .content > :last-child > :last-child, .exampleblock > .content .olist > ol > li:last-child > :last-child, .exampleblock > .content .ulist > ul > li:last-child > :last-child, .exampleblock > .content .qlist > ol > li:last-child > :last-child, .sidebarblock > .content > :last-child > :last-child, .sidebarblock > .content .olist > ol > li:last-child > :last-child, .sidebarblock > .content .ulist > ul > li:last-child > :last-child, .sidebarblock > .content .qlist > ol > li:last-child > :last-child { margin-bottom: 0; }
-You can specify that a parameter can receive an indefinite number of parameters, up to the next option. For example:
+.literalblock pre, .listingblock pre:not(.highlight), .listingblock pre[class="highlight"], .listingblock pre[class^="highlight "], .listingblock pre.CodeRay, .listingblock pre.prettyprint { background: rgba(16, 195, 196, 0.05); }
+.sidebarblock .literalblock pre, .sidebarblock .listingblock pre:not(.highlight), .sidebarblock .listingblock pre[class="highlight"], .sidebarblock .listingblock pre[class^="highlight "], .sidebarblock .listingblock pre.CodeRay, .sidebarblock .listingblock pre.prettyprint { background: #f2f1f1; }
-<pre class="brush: java">
-program -foo a1 a2 a3 -bar
-program -foo a1 -bar
-</pre>
+.literalblock pre, .literalblock pre[class], .listingblock pre, .listingblock pre[class] { border: 1px solid rgba(16, 195, 196, 0.125); -webkit-border-radius: 6px; border-radius: 6px; word-wrap: break-word; padding: 1em; font-size: 0.8125em; }
+.literalblock pre.nowrap, .literalblock pre[class].nowrap, .listingblock pre.nowrap, .listingblock pre[class].nowrap { overflow-x: auto; white-space: pre; word-wrap: normal; }
+@media only screen and (min-width: 768px) { .literalblock pre, .literalblock pre[class], .listingblock pre, .listingblock pre[class] { font-size: 0.90625em; } }
+@media only screen and (min-width: 1280px) { .literalblock pre, .literalblock pre[class], .listingblock pre, .listingblock pre[class] { font-size: 1em; } }
-Such a parameter must be of type <tt>List&lt;String&gt;</tt> and have the boolean <tt>variableArity</tt> set to <tt>true</tt>
+.literalblock.output pre { color: rgba(16, 195, 196, 0.05); background-color: inherit; }
-<pre class="brush: java">
-@Parameter(names = "-foo", variableArity = true)
-public List&lt;String&gt; foo = new ArrayList&lt;String&gt;();
-</pre>
+.listingblock pre.highlightjs { padding: 0; }
+.listingblock pre.highlightjs > code { padding: 1em; -webkit-border-radius: 6px; border-radius: 6px; }
-<h2><a class="section" name="Multiple_option_names">Multiple option names</a></h2>
+.listingblock > .content { position: relative; }
-You can specify more than one option name:
+.listingblock code[data-lang]:before { display: none; content: attr(data-lang); position: absolute; font-size: 0.75em; top: 0.425rem; right: 0.5rem; line-height: 1; text-transform: uppercase; color: #999; }
-<pre class="brush: java">
+.listingblock:hover code[data-lang]:before { display: block; }
- @Parameter(names = { "-d", "--outputDirectory" }, description = "Directory")
- private String outputDirectory;
+.listingblock.terminal pre .command:before { content: attr(data-prompt); padding-right: 0.5em; color: #999; }
-</pre>
+.listingblock.terminal pre .command:not([data-prompt]):before { content: "$"; }
-will allow both following syntaxes:
+table.pyhltable { border-collapse: separate; border: 0; margin-bottom: 0; background: none; }
-<pre class="brush: plain">
-java Main -d /tmp
-java Main --outputDirectory /tmp
-</pre>
+table.pyhltable td { vertical-align: top; padding-top: 0; padding-bottom: 0; line-height: 1.4; }
-<h2><a class="section" name="Other option configurations">Other option configurations</a></h2>
+table.pyhltable td.code { padding-left: .75em; padding-right: 0; }
-You can configure how options are looked up in a few different ways:
+pre.pygments .lineno, table.pyhltable td:not(.code) { color: #999; padding-left: 0; padding-right: .5em; border-right: 1px solid rgba(145, 135, 84, 0.15); }
-<ul>
- <li><tt>JCommander#setCaseSensitiveOptions(boolean)</tt>: specify whether options are case sensitive. If you call this method with <tt>false</tt>, then <tt>"-param"</tt> and
- <tt>"-PARAM"</tt> are considered equal.
- </li>
- <li><tt>JCommander#setAllowAbbreviatedOptions(boolean)</tt>: specify whether users can
- pass abbreviated options. If you call this method with <tt>true</tt> then users
- can pass <tt>"-par"</tt> to specify an option called <tt>-param</tt>. JCommander will
- throw a <tt>ParameterException</tt> if the abbreviated name is ambiguous.
- </li>
-</ul>
+pre.pygments .lineno { display: inline-block; margin-right: .25em; }
-<h2><a class="section" name="Required_and_optional">Required and optional parameters</a></h2>
+table.pyhltable .linenodiv { background: none !important; padding-right: 0 !important; }
-If some of your parameters are mandatory, you can use the
-<tt>required</tt> attribute (which default to <tt>false</tt>):
+.quoteblock { margin: 0 1em 1.25em 1.5em; display: table; }
+.quoteblock > .title { margin-left: -1.5em; margin-bottom: 0.75em; }
+.quoteblock blockquote, .quoteblock blockquote p { color: #999999; font-size: 1.15rem; line-height: 1.75; word-spacing: 0.1em; letter-spacing: 0; font-style: italic; text-align: justify; }
+.quoteblock blockquote { margin: 0; padding: 0; border: 0; }
+.quoteblock blockquote:before { content: "\201c"; float: left; font-size: 2.75em; font-weight: bold; line-height: 0.6em; margin-left: -0.6em; color: #002c5e; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1); }
+.quoteblock blockquote > .paragraph:last-child p { margin-bottom: 0; }
+.quoteblock .attribution { margin-top: 0.5em; margin-right: 0.5ex; text-align: right; }
+.quoteblock .quoteblock { margin-left: 0; margin-right: 0; padding: 0.5em 0; border-left: 3px solid #666666; }
+.quoteblock .quoteblock blockquote { padding: 0 0 0 0.75em; }
+.quoteblock .quoteblock blockquote:before { display: none; }
-<pre class="brush: java">
+.verseblock { margin: 0 1em 1.25em 1em; }
+.verseblock pre { font-family: "Open Sans", "DejaVu Sans", sans; font-size: 1.15rem; color: #999999; font-weight: 300; text-rendering: optimizeLegibility; }
+.verseblock pre strong { font-weight: 400; }
+.verseblock .attribution { margin-top: 1.25rem; margin-left: 0.5ex; }
- @Parameter(names = "-host", required = true)
- private String host;
+.quoteblock .attribution, .verseblock .attribution { font-size: 0.8125em; line-height: 1.45; font-style: italic; }
+.quoteblock .attribution br, .verseblock .attribution br { display: none; }
+.quoteblock .attribution cite, .verseblock .attribution cite { display: block; letter-spacing: -0.025em; color: #666666; }
-</pre>
+.quoteblock.abstract { margin: 0 0 1.25em 0; display: block; }
+.quoteblock.abstract blockquote, .quoteblock.abstract blockquote p { text-align: left; word-spacing: 0; }
+.quoteblock.abstract blockquote:before, .quoteblock.abstract blockquote p:first-of-type:before { display: none; }
-If this parameter is not specified, JCommander will throw an exception
-telling you which options are missing.
+table.tableblock { max-width: 100%; border-collapse: separate; }
+table.tableblock td > .paragraph:last-child p > p:last-child, table.tableblock th > p:last-child, table.tableblock td > p:last-child { margin-bottom: 0; }
-<h2><a class="section" name="Default_values">Default values</a></h2>
+table.tableblock, th.tableblock, td.tableblock { border: 0 solid rgba(145, 135, 84, 0.15); }
-The most common way to specify a default value for your parameters is to initialize the field at declaration time:
+table.grid-all th.tableblock, table.grid-all td.tableblock { border-width: 0 1px 1px 0; }
-<pre class="brush: java">
-private Integer logLevel = 3;
-</pre>
+table.grid-all tfoot > tr > th.tableblock, table.grid-all tfoot > tr > td.tableblock { border-width: 1px 1px 0 0; }
-For more complicated cases, you might want to be able to reuse identical default values across several main classes or be able to specify these default values in a centralized location such as a .properties or an XML fie. In this case, you can use an <tt>IDefaultProvider</tt>
+table.grid-cols th.tableblock, table.grid-cols td.tableblock { border-width: 0 1px 0 0; }
-<pre class="brush: java">
-public interface IDefaultProvider {
- /**
- * @param optionName The name of the option as specified in the names() attribute
- * of the @Parameter option (e.g. "-file").
- *
- * @return the default value for this option.
- */
- String getDefaultValueFor(String optionName);
-}
-</pre>
+table.grid-all * > tr > .tableblock:last-child, table.grid-cols * > tr > .tableblock:last-child { border-right-width: 0; }
-By passing an implementation of this interface to your <tt>JCommander</tt> object, you can now control which default value will be used for your options. Note that the value returned by this method will then be passed to a string converter, if any is applicable, thereby allowing you to specify default values for any types you need.
+table.grid-rows th.tableblock, table.grid-rows td.tableblock { border-width: 0 0 1px 0; }
-<p>
+table.grid-all tbody > tr:last-child > th.tableblock, table.grid-all tbody > tr:last-child > td.tableblock, table.grid-all thead:last-child > tr > th.tableblock, table.grid-rows tbody > tr:last-child > th.tableblock, table.grid-rows tbody > tr:last-child > td.tableblock, table.grid-rows thead:last-child > tr > th.tableblock { border-bottom-width: 0; }
-For example, here is a default provider that will assign a default value of 42 for all your parameters except "-debug":
+table.grid-rows tfoot > tr > th.tableblock, table.grid-rows tfoot > tr > td.tableblock { border-width: 1px 0 0 0; }
-<pre class="brush: java">
-private static final IDefaultProvider DEFAULT_PROVIDER = new IDefaultProvider() {
- @Override
- public String getDefaultValueFor(String optionName) {
- return "-debug".equals(optionName) ? "false" : "42";
- }
-};
+table.frame-all { border-width: 1px; }
-// ...
+table.frame-sides { border-width: 0 1px; }
-JCommander jc = new JCommander(new Args());
-jc.setDefaultProvider(DEFAULT_PROVIDER);
-</pre>
+table.frame-topbot { border-width: 1px 0; }
-<h2><a class="section" name="Help_parameter">Help parameter</a></h2>
+th.halign-left, td.halign-left { text-align: left; }
-If one of your parameters is used to display some help or usage, you need use the <tt>help</tt> attribute:
+th.halign-right, td.halign-right { text-align: right; }
-<pre class="brush: java">
- @Parameter(names = "--help", help = true)
- private boolean help;
-</pre>
+th.halign-center, td.halign-center { text-align: center; }
-If you omit this boolean, JCommander will instead issue an error message when it tries to validate your command and it finds that you didn't specify some of the required parameters.
+th.valign-top, td.valign-top { vertical-align: top; }
-<h2><a class="section" name="Complex">More complex syntaxes (commands)</a></h2>
+th.valign-bottom, td.valign-bottom { vertical-align: bottom; }
-Complex tools such as <tt>git</tt> or <tt>svn</tt> understand a whole set of commands, each of which with their own specific syntax:
+th.valign-middle, td.valign-middle { vertical-align: middle; }
-<pre class="brush: plain">
- git commit --amend -m "Bug fix"
-</pre>
+table thead th, table tfoot th { font-weight: bold; }
-Words such as "commit" above are called "commands" in JCommander, and you can specify them by creating one arg object per command:
+tbody tr th { display: table-cell; line-height: 1.5; background: rgba(119, 84, 22, 0.1); }
-<pre class="brush: java">
-@Parameters(separators = "=", commandDescription = "Record changes to the repository")
-private class CommandCommit {
+tbody tr th, tbody tr th p, tfoot tr th, tfoot tr th p { color: rgba(0, 0, 0, 0.8); font-weight: bold; }
- @Parameter(description = "The list of files to commit")
- private List&lt;String&gt; files;
+p.tableblock > code:only-child { background: none; padding: 0; }
- @Parameter(names = "--amend", description = "Amend")
- private Boolean amend = false;
+p.tableblock { font-size: 1em; }
- @Parameter(names = "--author")
- private String author;
-}
-</pre>
+td > div.verse { white-space: pre; }
-<pre class="brush: java">
-@Parameters(commandDescription = "Add file contents to the index")
-public class CommandAdd {
+ol { margin-left: 1.75em; }
- @Parameter(description = "File patterns to add to the index")
- private List&lt;String&gt; patterns;
+ul li ol { margin-left: 1.5em; }
- @Parameter(names = "-i")
- private Boolean interactive = false;
-}
-</pre>
+dl dd { margin-left: 1.125em; }
-Then you register these commands with your JCommander object. After the parsing phase, you call <tt>getParsedCommand()</tt> on your JCommander object, and based on the command that is returned, you know which arg object to inspect (you can still use a main arg object if you want to support options before the first command appears on the command line):
+dl dd:last-child, dl dd:last-child > :last-child { margin-bottom: 0; }
-<pre class="brush: java">
-CommandMain cm = new CommandMain();
-JCommander jc = new JCommander(cm);
+ol > li p, ul > li p, ul dd, ol dd, .olist .olist, .ulist .ulist, .ulist .olist, .olist .ulist { margin-bottom: 0.625em; }
-CommandAdd add = new CommandAdd();
-jc.addCommand("add", add);
-CommandCommit commit = new CommandCommit();
-jc.addCommand("commit", commit);
+ul.unstyled, ol.unnumbered, ul.checklist, ul.none { list-style-type: none; }
-jc.parse("-v", "commit", "--amend", "--author=cbeust", "A.java", "B.java");
+ul.unstyled, ol.unnumbered, ul.checklist { margin-left: 0.625em; }
-Assert.assertTrue(cm.verbose);
-Assert.assertEquals(jc.getParsedCommand(), "commit");
-Assert.assertTrue(commit.amend);
-Assert.assertEquals(commit.author, "cbeust");
-Assert.assertEquals(commit.files, Arrays.asList("A.java", "B.java"));
-</pre>
+ul.checklist li > p:first-child > .fa-square-o:first-child, ul.checklist li > p:first-child > .fa-check-square-o:first-child { width: 1em; font-size: 0.85em; }
-<h2><a class="section" name="Exceptions">Exception</a></h2>
+ul.checklist li > p:first-child > input[type="checkbox"]:first-child { width: 1em; position: relative; top: 1px; }
-Whenever JCommander detects an error, it will throw a
-<tt>ParameterException</tt>. Note that this is a Runtime Exception,
-since your application is probably not initialized correctly at this
-point.
+ul.inline { margin: 0 auto 0.625em auto; margin-left: -1.375em; margin-right: 0; padding: 0; list-style: none; overflow: hidden; }
+ul.inline > li { list-style: none; float: left; margin-left: 1.375em; display: block; }
+ul.inline > li > * { display: block; }
+.unstyled dl dt { font-weight: normal; font-style: normal; }
-<h2><a class="section" name="Usage">Usage</a></h2>
+ol.arabic { list-style-type: decimal; }
-You can invoke <tt>usage()</tt> on the <tt>JCommander</tt> instance that you used to parse your command line in order to generate a summary of all the options that your program understands:
+ol.decimal { list-style-type: decimal-leading-zero; }
-<pre class="brush: plain">
-Usage: &lt;main class&gt; [options]
- Options:
- -debug Debug mode (default: false)
- -groups Comma-separated list of group names to be run
- * -log, -verbose Level of verbosity (default: 1)
- -long A long number (default: 0)
-</pre>
+ol.loweralpha { list-style-type: lower-alpha; }
-You can customize the name of your program by calling <tt>setProgramName()</tt> on your <tt>JCommander</tt> object.
+ol.upperalpha { list-style-type: upper-alpha; }
-Options preceded by an asterisk are required.
+ol.lowerroman { list-style-type: lower-roman; }
-<h2><a class="section" name="Hiding">Hiding parameters</a></h2>
+ol.upperroman { list-style-type: upper-roman; }
-If you don't want certain parameters to appear in the usage, you can mark them as "hidden":
+ol.lowergreek { list-style-type: lower-greek; }
-<pre class="brush: java">
-@Parameter(names = "-debug", description = "Debug mode", hidden = true)
-private boolean debug = false;
-</pre>
+.hdlist > table, .colist > table { border: 0; background: none; }
+.hdlist > table > tbody > tr, .colist > table > tbody > tr { background: none; }
-<h2><a class="section" name="Internationalization">Internationalization</a></h2>
+td.hdlist1, td.hdlist2 { vertical-align: top; padding: 0 0.625em; }
-You can internationalize the descriptions of your parameters.
+td.hdlist1 { font-weight: bold; padding-bottom: 1.25em; }
-<p>
+.literalblock + .colist, .listingblock + .colist { margin-top: -0.5em; }
-First you use the <tt>@Parameters</tt> annotation at the top of your class to define the name of your message bundle, and then you use the <tt>descriptionKey</tt> attribute instead of <tt>description</tt> on all the <tt>@Parameters</tt> that require translations. This <tt>descriptionKey</tt> is the key to the string into your message bundle:
+.colist > table tr > td:first-of-type { padding: 0 0.75em; line-height: 1; }
+.colist > table tr > td:first-of-type img { max-width: initial; }
+.colist > table tr > td:last-of-type { padding: 0.25em 0; }
-<h3 class="sourcetitle">I18N.java</h3>
-<pre class="brush:java">
-@Parameters(resourceBundle = "MessageBundle")
-private class ArgsI18N2 {
- @Parameter(names = "-host", description = "Host", descriptionKey = "host")
- String hostName;
-}
-</pre>
+.thumb, .th { line-height: 0; display: inline-block; border: solid 4px white; -webkit-box-shadow: 0 0 0 1px #dddddd; box-shadow: 0 0 0 1px #dddddd; }
-Your bundle needs to define this key:
+.imageblock.left, .imageblock[style*="float: left"] { margin: 0.25em 0.625em 1.25em 0; }
+.imageblock.right, .imageblock[style*="float: right"] { margin: 0.25em 0 1.25em 0.625em; }
+.imageblock > .title { margin-bottom: 0; }
+.imageblock.thumb, .imageblock.th { border-width: 6px; }
+.imageblock.thumb > .title, .imageblock.th > .title { padding: 0 0.125em; }
-<br>
+.image.left, .image.right { margin-top: 0.25em; margin-bottom: 0.25em; display: inline-block; line-height: 0; }
+.image.left { margin-right: 0.625em; }
+.image.right { margin-left: 0.625em; }
-<h3 class="sourcetitle">MessageBundle_fr_FR.properties</h3>
-<pre class="brush: plain">
-host: H&ocirc;te
-</pre>
+a.image { text-decoration: none; display: inline-block; }
+a.image object { pointer-events: none; }
-JCommander will then use the default locale to resolve your descriptions.
+sup.footnote, sup.footnoteref { font-size: 0.875em; position: static; vertical-align: super; }
+sup.footnote a, sup.footnoteref a { text-decoration: none; }
+sup.footnote a:active, sup.footnoteref a:active { text-decoration: underline; }
-<h2><a class="section" name="Parameter_delegates">Parameter delegates</a></h2>
+#footnotes { padding-top: 0.75em; padding-bottom: 0.75em; margin-bottom: 0.625em; }
+#footnotes hr { width: 20%; min-width: 6.25em; margin: -0.25em 0 0.75em 0; border-width: 1px 0 0 0; }
+#footnotes .footnote { padding: 0 0.375em 0 0.225em; line-height: 1.3334; font-size: 0.875em; margin-left: 1.2em; text-indent: -1.05em; margin-bottom: 0.2em; }
+#footnotes .footnote a:first-of-type { font-weight: bold; text-decoration: none; }
+#footnotes .footnote:last-of-type { margin-bottom: 0; }
+#content #footnotes { margin-top: -0.625em; margin-bottom: 0; padding: 0.75em 0; }
-If you are writing many different tools in the same project, you will probably find that most of these tools can share configurations. While you can use inheritance with your objects to avoid repeating this code, the restriction to single inheritance of implementation might limit your flexibility. To address this problem, JCommander supports parameter delegates.
+.gist .file-data > table { border: 0; background: #fff; width: 100%; margin-bottom: 0; }
+.gist .file-data > table td.line-data { width: 99%; }
-<p>
+div.unbreakable { page-break-inside: avoid; }
-When JCommander encounters an object annotated with <tt>@ParameterDelegate</tt> in one of your objects, it acts as if this object had been added as a description object itself:
+.big { font-size: larger; }
-<pre class="brush: java">
-class Delegate {
- @Parameter(names = "-port")
- private int port;
-}
+.small { font-size: smaller; }
-class MainParams {
- @Parameter(names = "-v")
- private boolean verbose;
+.underline { text-decoration: underline; }
- @ParametersDelegate
- private Delegate delegate = new Delegate();
-}
-</pre>
+.overline { text-decoration: overline; }
-The example above specifies a delegate parameter <tt>Delegate</tt> which is then referenced in <tt>MainParams</tt>. You only need to add a <tt>MainParams</tt> object to your JCommander configuration in order to use the delegate:
+.line-through { text-decoration: line-through; }
-<pre class="brush: java">
-MainParams p = new MainParams();
-new JCommander(p).parse("-v", "-port", "1234");
-Assert.assertTrue(p.isVerbose);
-Assert.assertEquals(p.delegate.port, 1234);
-</pre>
+.aqua { color: #00bfbf; }
+
+.aqua-background { background-color: #00fafa; }
+
+.black { color: black; }
+
+.black-background { background-color: black; }
+
+.blue { color: #0000bf; }
+
+.blue-background { background-color: #0000fa; }
+
+.fuchsia { color: #bf00bf; }
+
+.fuchsia-background { background-color: #fa00fa; }
+
+.gray { color: #606060; }
+
+.gray-background { background-color: #7d7d7d; }
+
+.green { color: #006000; }
+
+.green-background { background-color: #007d00; }
+
+.lime { color: #00bf00; }
+
+.lime-background { background-color: #00fa00; }
+
+.maroon { color: #600000; }
+
+.maroon-background { background-color: #7d0000; }
+
+.navy { color: #000060; }
+
+.navy-background { background-color: #00007d; }
+
+.olive { color: #606000; }
+
+.olive-background { background-color: #7d7d00; }
+
+.purple { color: #600060; }
+
+.purple-background { background-color: #7d007d; }
+
+.red { color: #bf0000; }
+
+.red-background { background-color: #fa0000; }
+
+.silver { color: #909090; }
+
+.silver-background { background-color: #bcbcbc; }
+
+.teal { color: #006060; }
+
+.teal-background { background-color: #007d7d; }
+
+.white { color: #bfbfbf; }
+
+.white-background { background-color: #fafafa; }
+
+.yellow { color: #bfbf00; }
+
+.yellow-background { background-color: #fafa00; }
+
+span.icon > .fa { cursor: default; }
-<h2><a class="section" name="DynamicParameters">Dynamic parameters</a></h2>
+.admonitionblock td.icon [class^="fa icon-"] { font-size: 2.5em; text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5); cursor: default; }
+.admonitionblock td.icon .icon-note:before { content: "\f05a"; color: #004060; }
+.admonitionblock td.icon .icon-tip:before { content: "\f0eb"; text-shadow: 1px 1px 2px rgba(155, 155, 0, 0.8); color: #111; }
+.admonitionblock td.icon .icon-warning:before { content: "\f071"; color: #bf6900; }
+.admonitionblock td.icon .icon-caution:before { content: "\f06d"; color: #bf3400; }
+.admonitionblock td.icon .icon-important:before { content: "\f06a"; color: #bf0000; }
-JCommander allows you to specify parameters that are not known at compile time, such as <tt>"-Da=b -Dc=d"</tt>. Such parameters are specified with the <tt><a href="apidocs/com/beust/jcommander/DynamicParameter.html">@DynamicParameter</a></tt> annotation and must be of type <tt>Map&lt;String, String&gt;</tt>. Dynamic parameters are allowed to appear multiple times on the command line:
+.conum[data-value] { display: inline-block; color: #fff !important; background-color: rgba(0, 0, 0, 0.8); -webkit-border-radius: 100px; border-radius: 100px; text-align: center; font-size: 0.75em; width: 1.67em; height: 1.67em; line-height: 1.67em; font-family: "Open Sans", "DejaVu Sans", sans-serif; font-style: normal; font-weight: bold; }
+.conum[data-value] * { color: #fff !important; }
+.conum[data-value] + b { display: none; }
+.conum[data-value]:after { content: attr(data-value); }
+pre .conum[data-value] { position: relative; top: -0.125em; }
-<pre class="brush: java">
-@DynamicParameter(names = "-D", description = "Dynamic parameters go here")
-private Map&lt;String, String&gt; params = new HashMap&lt;String, String&gt;();
-</pre>
+b.conum * { color: inherit !important; }
-You can specify a different assignment string than <tt>=</tt> by using the attribute <tt>assignment</tt>.
+.conum:not([data-value]):empty { display: none; }
-<h2><a class="section" name="Scala">JCommander in Scala</a></h2>
+#toc.toc2 ul ul { list-style-type: circle; padding-left: 2em; }
-Here is a quick example of how to use JCommander in Scala (courtesy of Patrick Linskey):
+.sect1 { padding-bottom: 0 !important; margin-bottom: 2.5em; }
-<pre class="brush: java">
-import java.io.File
-import com.beust.jcommander.{JCommander, Parameter}
-import collection.JavaConversions._
+#header h1 { font-weight: bold; position: relative; left: -0.0625em; }
-object Main {
- object Args {
- // Declared as var because JCommander assigns a new collection declared
- // as java.util.List because that's what JCommander will replace it with.
- // It'd be nice if JCommander would just use the provided List so this
- // could be a val and a Scala LinkedList.
- @Parameter(
- names = Array("-f", "--file"),
- description = "File to load. Can be specified multiple times.")
- var file: java.util.List[String] = null
+#content h2, #content h3, #content #toctitle, #content .sidebarblock > .content > .title, #content h4, #content h5, #content #toctitle { position: relative; left: -0.0625em; }
+#content h2 { font-weight: bold; }
+
+.paragraph.lead > p, #preamble > .sectionbody > .paragraph:first-of-type p { color: black; }
+
+pre.pygments.highlight { background-color: rgba(16, 195, 196, 0.05); }
+
+.pygments .tok-err { border: none !important; color: #800000 !important; }
+
+.pygments .tok-c { color: #999 !important; }
+
+</style>
+</head>
+<body class="article toc2 toc-left">
+<div id="header">
+<h1>JCommander</h1>
+<div class="details">
+<span id="author" class="author">Cédric Beust</span><br>
+<span id="email" class="email"><a href="mailto:cedric@beust.com">cedric@beust.com</a></span><br>
+</div>
+<div id="toc" class="toc2">
+<div id="toctitle">Table of Contents</div>
+<ul class="sectlevel1">
+<li><a href="#_overview">1. Overview</a></li>
+<li><a href="#_types_of_options">2. Types of options</a>
+<ul class="sectlevel2">
+<li><a href="#_boolean">2.1. Boolean</a></li>
+<li><a href="#_lists">2.2. Lists</a></li>
+<li><a href="#_password">2.3. Password</a></li>
+<li><a href="#_echo_input">2.4. Echo Input</a></li>
+</ul>
+</li>
+<li><a href="#_custom_types_converters_and_splitters">3. Custom types (converters and splitters)</a>
+<ul class="sectlevel2">
+<li><a href="#single-value">3.1. Custom types - Single value</a></li>
+<li><a href="#list-value">3.2. Custom types - List value</a></li>
+<li><a href="#_splitting">3.3. Splitting</a></li>
+</ul>
+</li>
+<li><a href="#_parameter_validation">4. Parameter validation</a>
+<ul class="sectlevel2">
+<li><a href="#_individual_parameter_validation">4.1. Individual parameter validation</a></li>
+<li><a href="#_global_parameter_validation">4.2. Global parameter validation</a></li>
+</ul>
+</li>
+<li><a href="#_main_parameter">5. Main parameter</a></li>
+<li><a href="#_private_parameters">6. Private parameters</a></li>
+<li><a href="#_parameter_separators">7. Parameter separators</a></li>
+<li><a href="#_multiple_descriptions">8. Multiple descriptions</a></li>
+<li><a href="#__syntax">9. @ syntax</a></li>
+<li><a href="#_arities_multiple_values_for_parameters">10. Arities (multiple values for parameters)</a>
+<ul class="sectlevel2">
+<li><a href="#_fixed_arities">10.1. Fixed arities</a></li>
+<li><a href="#_variable_arities">10.2. Variable arities</a></li>
+</ul>
+</li>
+<li><a href="#_multiple_option_names">11. Multiple option names</a></li>
+<li><a href="#_other_option_configurations">12. Other option configurations</a></li>
+<li><a href="#_required_and_optional_parameters">13. Required and optional parameters</a></li>
+<li><a href="#_default_values">14. Default values</a></li>
+<li><a href="#_help_parameter">15. Help parameter</a></li>
+<li><a href="#_more_complex_syntaxes_commands">16. More complex syntaxes (commands)</a></li>
+<li><a href="#_exception">17. Exception</a></li>
+<li><a href="#_usage">18. Usage</a></li>
+<li><a href="#_hiding_parameters">19. Hiding parameters</a></li>
+<li><a href="#_internationalization">20. Internationalization</a></li>
+<li><a href="#_parameter_delegates">21. Parameter delegates</a></li>
+<li><a href="#_dynamic_parameters">22. Dynamic parameters</a></li>
+<li><a href="#_jcommander_in_other_languages">23. JCommander in other languages</a>
+<ul class="sectlevel2">
+<li><a href="#_kotlin">23.1. Kotlin</a></li>
+<li><a href="#_groovy">23.2. Groovy</a></li>
+</ul>
+</li>
+<li><a href="#_more_examples">24. More examples</a></li>
+<li><a href="#_mailing_list">25. Mailing list</a></li>
+<li><a href="#_javadocs">26. Javadocs</a></li>
+<li><a href="#_license">27. License</a></li>
+<li><a href="#_download">28. Download</a></li>
+</ul>
+</div>
+</div>
+<div id="content">
+<div id="preamble">
+<div class="sectionbody">
+<div style="float:right">
+<div style="display:inline-block">
+ <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
+ <input type="hidden" name="cmd" value="_donations">
+ <input type="hidden" name="business" value="cedric@beust.com">
+ <input type="hidden" name="lc" value="US">
+ <input type="hidden" name="item_name" value="Cedric Beust">
+ <input type="hidden" name="no_note" value="0">
+ <input type="hidden" name="currency_code" value="USD">
+ <input type="hidden" name="bn" value="PP-DonationsBF:btn_donate_LG.gif:NonHostedGuest">
+ <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
+ <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1" hidden="" style="display: none !important;">
+ </form>
+</div>
+</div>
+<div class="paragraph">
+<p><em>"Because life is too short to parse command line parameters"</em></p>
+</div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_overview">1. Overview</h2>
+<div class="sectionbody">
+<div class="paragraph">
+<p>JCommander is a very small Java framework that makes it trivial to parse command line parameters.
+You annotate fields with descriptions of your options:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">import com.beust.jcommander.Parameter;
+
+public class Args {
+ @Parameter
+ private List&lt;String&gt; parameters = new ArrayList&lt;&gt;();
+
+ @Parameter(names = { "-log", "-verbose" }, description = "Level of verbosity")
+ private Integer verbose = 1;
+
+ @Parameter(names = "-groups", description = "Comma-separated list of group names to be run")
+ private String groups;
+
+ @Parameter(names = "-debug", description = "Debug mode")
+ private boolean debug = false;
+}</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>and then you simply ask JCommander to parse:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">Args args = new Args();
+String[] argv = { "-log", "2", "-groups", "unit" };
+JCommander.newBuilder()
+ .addObject(args)
+ .build()
+ .parse(argv);
+
+Assert.assertEquals(jct.verbose.intValue(), 2);</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>Here is another example:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">class Main {
+ @Parameter(names={"--length", "-l"})
+ int length;
+ @Parameter(names={"--pattern", "-p"})
+ int pattern;
+
+ public static void main(String ... argv) {
+ Main main = new Main();
+ JCommander.newBuilder()
+ .addObject(main)
+ .build()
+ .parse(argv);
+ main.run();
+ }
+
+ public void run() {
+ System.out.printf("%d %d", length, pattern);
+ }
+}</code></pre>
+</div>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-bash" data-lang="bash">$ java Main -l 512 --pattern 2
+512 2</code></pre>
+</div>
+</div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_types_of_options">2. Types of options</h2>
+<div class="sectionbody">
+<div class="paragraph">
+<p>The fields representing your parameters can be of any type. Basic types (<code>Integer</code>, <code>Boolean</code>, etc&#8230;&#8203;) are supported by default and you can write type converters to support any other type (<code>File</code>, etc&#8230;&#8203;).</p>
+</div>
+<div class="sect2">
+<h3 id="_boolean">2.1. Boolean</h3>
+<div class="paragraph">
+<p>When a Parameter annotation is found on a field of type <code>boolean</code> or <code>Boolean</code>, JCommander interprets it as an option with an arity of 0:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">@Parameter(names = "-debug", description = "Debug mode")
+private boolean debug = false;</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>Such a parameter does not require any additional parameter on the command line and if it&#8217;s detected during parsing, the corresponding field will be set to true. If you want to define a boolean parameter that&#8217;s true by default, you can declare it as having an arity of 1. Users will then have to specify the value they want explicitly:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">@Parameter(names = "-debug", description = "Debug mode", arity = 1)
+private boolean debug = true;</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>Invoke with either of:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-bash" data-lang="bash">program -debug true
+program -debug false</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>When a Parameter annotation is found on a field of type <code>String</code>, <code>Integer</code>, <code>int</code>, <code>Long</code> or <code>long</code>, JCommander will parse the following parameter and it will attempt to cast it to the right type:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">@Parameter(names = "-log", description = "Level of verbosity")
+private Integer verbose = 1;</code></pre>
+</div>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-bash" data-lang="bash">java Main -log 3</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>will cause the field verbose to receive the value 3. However:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-bash" data-lang="bash">$ java Main -log test</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>will cause an exception to be thrown.</p>
+</div>
+</div>
+<div class="sect2">
+<h3 id="_lists">2.2. Lists</h3>
+<div class="paragraph">
+<p>When a Parameter annotation is found on a field of type <code>List</code>, JCommander will interpret it as an option that can occur multiple times:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">@Parameter(names = "-host", description = "The host")
+private List&lt;String&gt; hosts = new ArrayList&lt;&gt;();</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>will allow you to parse the following command line:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-bash" data-lang="bash">$ java Main -host host1 -verbose -host host2</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>When JCommander is done parsing the line above, the field hosts will contain the strings <code>"host1"</code> and <code>"host2"</code>.</p>
+</div>
+</div>
+<div class="sect2">
+<h3 id="_password">2.3. Password</h3>
+<div class="paragraph">
+<p>If one of your parameters is a password or some other value that you do not wish to appear in your history or in clear, you can declare it of type password and JCommander will then ask you to enter it in the console:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">public class ArgsPassword {
+ @Parameter(names = "-password", description = "Connection password", password = true)
+ private String password;
+}</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>When you run your program, you will get the following prompt:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-bash" data-lang="bash">Value for -password (Connection password):</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>You will need to type the value at this point before JCommander resumes.</p>
+</div>
+</div>
+<div class="sect2">
+<h3 id="_echo_input">2.4. Echo Input</h3>
+<div class="paragraph">
+<p>In Java 6, by default, you will not be able to see what you type for passwords entered at the prompt (Java 5 and lower will always show the password). However, you can override this by setting echoInput to <code>true</code> (default is <code>false</code> and this setting only has an effect when password is <code>true</code>):</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">public class ArgsPassword {
+ @Parameter(names = "-password", description = "Connection password", password = true, echoInput = true)
+ private String password;
+}</code></pre>
+</div>
+</div>
+</div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_custom_types_converters_and_splitters">3. Custom types (converters and splitters)</h2>
+<div class="sectionbody">
+<div class="paragraph">
+<p>To bind parameters to custom types or change the way how JCommander splits parameters (default is to split via comma) JCommander provides two
+interfaces <code>IStringConverter</code> and <code>IParameterSplitter</code>.</p>
+</div>
+<div class="sect2">
+<h3 id="single-value">3.1. Custom types - Single value</h3>
+<div class="paragraph">
+<p>Use either the <code>converter=</code> attribute of the <code>@Parameter</code> or implement <code>IStringConverterFactory</code>.</p>
+</div>
+<div class="sect3">
+<h4 id="_by_annotation">3.1.1. By annotation</h4>
+<div class="paragraph">
+<p>By default, JCommander parses the command line into basic types only (strings, booleans, integers and longs). Very often, your application actually needs more complex types (such as files, host names, lists, etc.). To achieve this, you can write a type converter by implementing the following interface:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">public interface IStringConverter&lt;T&gt; {
+ T convert(String value);
+}</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>For example, here is a converter that turns a string into a File:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">public class FileConverter implements IStringConverter&lt;File&gt; {
+ @Override
+ public File convert(String value) {
+ return new File(value);
+ }
+}</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>Then, all you need to do is declare your field with the correct type and specify the converter as an attribute:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">@Parameter(names = "-file", converter = FileConverter.class)
+File file;</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>JCommander ships with a few common converters (for more info please see the implementations of <code>IStringConverter</code>).</p>
+</div>
+<div class="sect4">
+<h5 id="_note">Note</h5>
+<div class="paragraph">
+<p>If a converter is used for a <code>List</code> field:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">@Parameter(names = "-files", converter = FileConverter.class)
+List&lt;File&gt; files;</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>And the application is called as follows:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-bash" data-lang="bash">$ java App -files file1,file2,file3</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>JCommander will split the string <code>file1,file2,file3</code> into <code>file1</code>, <code>file2</code>, <code>file3</code> and feed it one by one to the converter.</p>
+</div>
+<div class="paragraph">
+<p>For an alternative solution to parse a list of values, see <a href="#list-value">Custom types - List value</a>.</p>
+</div>
+</div>
+</div>
+<div class="sect3">
+<h4 id="_by_factory">3.1.2. By factory</h4>
+<div class="paragraph">
+<p>If the custom types you use appear multiple times in your application, having to specify the converter in each annotation can become tedious. To address this, you can use an <code>IStringConverterFactory</code>:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">public interface IStringConverterFactory {
+ &lt;T&gt; Class&lt;? extends IStringConverter&lt;T&gt;&gt; getConverter(Class&lt;T&gt; forType);
+}</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>For example, suppose you need to parse a string representing a host and a port:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-bash" data-lang="bash">$ java App -target example.com:8080</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>You define the holder class :</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">public class HostPort {
+ public HostPort(String host, String port) {
+ this.host = host;
+ this.port = port;
}
- def main(args: Array[String]): Unit = {
- new JCommander(Args, args.toArray: _*)
- for (filename <- Args.file) {
- val f = new File(filename)
- printf("file: %s\n", f.getName)
+ final String host;
+ final Integer port;
+}</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>and the string converter to create instances of this class:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">class HostPortConverter implements IStringConverter&lt;HostPort&gt; {
+ @Override
+ public HostPort convert(String value) {
+ String[] s = value.split(":");
+ return new HostPort(s[0], Integer.parseInt(s[1]));
+ }
+}</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>The factory is straightforward:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">public class Factory implements IStringConverterFactory {
+ public Class&lt;? extends IStringConverter&lt;?&gt;&gt; getConverter(Class forType) {
+ if (forType.equals(HostPort.class)) return HostPortConverter.class;
+ else return null;
+ }</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>You can now use the type <code>HostPort</code> as a parameter without any converterClass attribute:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">public class ArgsConverterFactory {
+ @Parameter(names = "-hostport")
+ private HostPort hostPort;
+}</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>All you need to do is add the factory to your JCommander object:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">ArgsConverterFactory a = new ArgsConverterFactory();
+JCommander jc = JCommander.newBuilder()
+ .addObject(a)
+ .addConverterFactory(new Factory())
+ .build()
+ .parse("-hostport", "example.com:8080");
+
+Assert.assertEquals(a.hostPort.host, "example.com");
+Assert.assertEquals(a.hostPort.port.intValue(), 8080);</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>Another advantage of using string converter factories is that your factories can come from a dependency injection framework.</p>
+</div>
+</div>
+</div>
+<div class="sect2">
+<h3 id="list-value">3.2. Custom types - List value</h3>
+<div class="paragraph">
+<p>Use the <code>listConverter=</code> attribute of the <code>@Parameter</code> annotation and assign a custom <code>IStringConverter</code> implementation to convert a <code>String</code> into a <code>List</code> of values.</p>
+</div>
+<div class="sect3">
+<h4 id="_by_annotation_2">3.2.1. By annotation</h4>
+<div class="paragraph">
+<p>If your application needs a list of complex types, write a list type converter by implementing the same interface as before:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">public interface IStringConverter&lt;T&gt; {
+ T convert(String value);
+}</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>where <code>T</code> is a <code>List</code>.</p>
+</div>
+<div class="paragraph">
+<p>For example, here is a list converter that turns a string into a <code>List&lt;File&gt;</code>:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">public class FileListConverter implements IStringConverter&lt;List&lt;File&gt;&gt; {
+ @Override
+ public List&lt;File&gt; convert(String files) {
+ String [] paths = files.split(",");
+ List&lt;File&gt; fileList = new ArrayList&lt;&gt;();
+ for(String path : paths){
+ fileList.add(new File(path));
}
+ return fileList;
+ }
+}</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>Then, all you need to do is declare your field with the correct type and specify the list converter as an attribute:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">@Parameter(names = "-files", listConverter = FileListConverter.class)
+List&lt;File&gt; file;</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>Now if you call for application as in the following example:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-bash" data-lang="bash">$ java App -files file1,file2,file3</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>The parameter <code>file1,file2,file3</code> is given to the <code>listConverter</code> and will the properly processed.</p>
+</div>
+<div class="paragraph">
+<p>JCommander ships with a default converter for <code>String</code> values.</p>
+</div>
+</div>
+</div>
+<div class="sect2">
+<h3 id="_splitting">3.3. Splitting</h3>
+<div class="paragraph">
+<p>Use the <code>splitter=</code> attribute of the <code>@Parameter</code> annotation and assign a custom <code>IParameterSplitter</code> implementation to handle how parameters are split in sub-parts.</p>
+</div>
+<div class="sect3">
+<h4 id="_by_annotation_3">3.3.1. By annotation</h4>
+<div class="paragraph">
+<p>By default, JCommander tries to split parameters for <code>List</code> field types on commas.</p>
+</div>
+<div class="paragraph">
+<p>To split parameters on other characters, you can write a custom splitter by implementing the following interface:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">public interface IParameterSplitter {
+ List&lt;String&gt; split(String value);
+}</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>For example, here is a splitter that splits a string on semicolon:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">public static class SemiColonSplitter implements IParameterSplitter {
+ public List&lt;String&gt; split(String value) {
+ return Arrays.asList(value.split(";"));
+ }
+}</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>Then, all you need to do is declare your field with the correct type and specify the splitter as an attribute:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">@Parameter(names = "-files", converter = FileConverter.class, splitter = SemiColonSplitter.class)
+List&lt;File&gt; files;</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>JCommander will split the string <code>file1;file2;file3</code> into <code>file1</code>, <code>file2</code>, <code>file3</code> and feed it one by one to the converter.</p>
+</div>
+</div>
+</div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_parameter_validation">4. Parameter validation</h2>
+<div class="sectionbody">
+<div class="paragraph">
+<p>Parameter validation can be performed in two different ways: at the individual parameter level or globally.</p>
+</div>
+<div class="sect2">
+<h3 id="_individual_parameter_validation">4.1. Individual parameter validation</h3>
+<div class="paragraph">
+<p>You can ask JCommander to perform early validation on your parameters by providing a class that implements the following interface:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">public interface IParameterValidator {
+ /**
+ * Validate the parameter.
+ *
+ * @param name The name of the parameter (e.g. "-host").
+ * @param value The value of the parameter that we need to validate
+ *
+ * @throws ParameterException Thrown if the value of the parameter is invalid.
+ */
+ void validate(String name, String value) throws ParameterException;
+}</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>Here is an example implementation that will make sure that the parameter is a positive integer:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">public class PositiveInteger implements IParameterValidator {
+ public void validate(String name, String value)
+ throws ParameterException {
+ int n = Integer.parseInt(value);
+ if (n &lt; 0) {
+ throw new ParameterException("Parameter " + name + " should be positive (found " + value +")");
+ }
+ }
+}</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>Specify the name of a class implementing this interface in the <code>validateWith</code> attribute of your <code>@Parameter</code> annotations:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">@Parameter(names = "-age", validateWith = PositiveInteger.class)
+private Integer age;</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>Attempting to pass a negative integer to this option will cause a ParameterException to be thrown.</p>
+</div>
+<div class="paragraph">
+<p>Multiple validators may be specified:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">@Parameter(names = "-count", validateWith = { PositiveInteger.class, CustomOddNumberValidator.class })
+private Integer value;</code></pre>
+</div>
+</div>
+</div>
+<div class="sect2">
+<h3 id="_global_parameter_validation">4.2. Global parameter validation</h3>
+<div class="paragraph">
+<p>After parsing your parameters with JCommander, you might want to perform additional validation across these parameters, such as making sure that two mutually exclusive parameters are not both specified. Because of all the potential combinations involved in such validation, JCommander does not provide any annotation-based solution to perform this validation because such an approach would necessarily be very limited by the very nature of Java annotations. Instead, you should simply perform this validation in Java on all the arguments that JCommander just parsed.</p>
+</div>
+</div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_main_parameter">5. Main parameter</h2>
+<div class="sectionbody">
+<div class="paragraph">
+<p>So far, all the <code>@Parameter</code> annotations we have seen had defined an attribute called <code>names</code>. You can define one (and at most one) parameter without any such attribute. This parameter needs to be a <code>List&lt;String&gt;</code> and it will contain all the parameters that are not options:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">@Parameter(description = "Files")
+private List&lt;String&gt; files = new ArrayList&lt;&gt;();
+
+@Parameter(names = "-debug", description = "Debugging level")
+private Integer debug = 1;</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>will allow you to parse:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-bash" data-lang="bash">$ java Main -debug file1 file2</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>and the field files will receive the strings <code>"file1"</code> and <code>"file2"</code>.</p>
+</div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_private_parameters">6. Private parameters</h2>
+<div class="sectionbody">
+<div class="paragraph">
+<p>Parameters can be private:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">public class ArgsPrivate {
+ @Parameter(names = "-verbose")
+ private Integer verbose = 1;
+
+ public Integer getVerbose() {
+ return verbose;
}
}
-</pre>
+ArgsPrivate args = new ArgsPrivate();
+JCommander.newBuilder()
+ .addObject(args)
+ .build()
+ .parse("-verbose", "3");
+Assert.assertEquals(args.getVerbose().intValue(), 3);</code></pre>
+</div>
+</div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_parameter_separators">7. Parameter separators</h2>
+<div class="sectionbody">
+<div class="paragraph">
+<p>By default, parameters are separated by spaces, but you can change this setting to allow different separators:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-bash" data-lang="bash">$ java Main -log:3</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>or</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-bash" data-lang="bash">$ java Main -level=42</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>You define the separator with the @Parameters annotation:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">@Parameters(separators = "=")
+public class SeparatorEqual {
+ @Parameter(names = "-level")
+ private Integer level = 2;
+}</code></pre>
+</div>
+</div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_multiple_descriptions">8. Multiple descriptions</h2>
+<div class="sectionbody">
+<div class="paragraph">
+<p>You can spread the description of your parameters on more than one class. For example, you can define the following two classes:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">public class ArgsMaster {
+ @Parameter(names = "-master")
+ private String master;
+}
-<h2><a class="section" name="Groovy">JCommander in Groovy</a></h2>
+public class ArgsSlave {
+ @Parameter(names = "-slave")
+ private String slave;
+}</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>and pass these two objects to JCommander:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">ArgsMaster m = new ArgsMaster();
+ArgsSlave s = new ArgsSlave();
+String[] argv = { "-master", "master", "-slave", "slave" };
+JCommander.newBuilder()
+ .addObject(new Object[] { m , s })
+ .build()
+ .parse(argv);
-Here is a quick example of how to use JCommander in Groovy (courtesy of Paul King):
+Assert.assertEquals(m.master, "master");
+Assert.assertEquals(s.slave, "slave");</code></pre>
+</div>
+</div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="__syntax">9. @ syntax</h2>
+<div class="sectionbody">
+<div class="paragraph">
+<p>JCommander supports the @ syntax, which allows you to put all your options into a file and pass this file as parameter:</p>
+</div>
+<div id="app-listing" class="listingblock">
+<div class="title">/tmp/parameters</div>
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-bash" data-lang="bash">-verbose
+file1
+file2
+file3</code></pre>
+</div>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-bash" data-lang="bash">$ java Main @/tmp/parameters</code></pre>
+</div>
+</div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_arities_multiple_values_for_parameters">10. Arities (multiple values for parameters)</h2>
+<div class="sectionbody">
+<div class="sect2">
+<h3 id="_fixed_arities">10.1. Fixed arities</h3>
+<div class="paragraph">
+<p>If some of your parameters require more than one value, such as the following example where two values are expected after -pairs:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-bash" data-lang="bash">$ java Main -pairs slave master foo.xml</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>then you need to define your parameter with the arity attribute and make that parameter a <code>List&lt;String&gt;</code>:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">@Parameter(names = "-pairs", arity = 2, description = "Pairs")
+private List&lt;String&gt; pairs;</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>You don&#8217;t need to specify an arity for parameters of type <code>boolean</code> or <code>Boolean</code> (which have a default arity of 0) and of types <code>String</code>, <code>Integer</code>, <code>int</code>, <code>Long</code> and <code>long</code> (which have a default arity of 1).</p>
+</div>
+<div class="paragraph">
+<p>Also, note that only <code>List&lt;String&gt;</code> is allowed for parameters that define an arity. You will have to convert these values yourself if the parameters you need are of type <code>Integer</code> or other (this limitation is due to Java&#8217;s erasure).</p>
+</div>
+</div>
+<div class="sect2">
+<h3 id="_variable_arities">10.2. Variable arities</h3>
+<div class="paragraph">
+<p>You can specify that a parameter can receive an indefinite number of parameters, up to the next option. For example:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-bash" data-lang="bash">program -foo a1 a2 a3 -bar
+program -foo a1 -bar</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>Such a parameter can be parsed in two different ways.</p>
+</div>
+<div class="sect3">
+<h4 id="_with_a_list">10.2.1. With a list</h4>
+<div class="paragraph">
+<p>If the number of following parameters is unknown, your parameter must be of type <code>List&lt;String&gt;</code> and you
+need to set the boolean <code>variableArity</code> to <code>true</code>:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">@Parameter(names = "-foo", variableArity = true)
+public List&lt;String&gt; foo = new ArrayList&lt;&gt;();</code></pre>
+</div>
+</div>
+</div>
+<div class="sect3">
+<h4 id="_with_a_class">10.2.2. With a class</h4>
+<div class="paragraph">
+<p>Alternatively, you can define a class in which the following parameters will be stored, based on their order
+of appearance:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">static class MvParameters {
+ @SubParameter(order = 0)
+ String from;
+
+ @SubParameter(order = 1)
+ String to;
+}
+@Test
+public void arity() {
+ class Parameters {
+ @Parameter(names = {"--mv"}, arity = 2)
+ private MvParameters mvParameters;
+ }
-<pre class="brush: java">
-import com.beust.jcommander.*
+ Parameters args = new Parameters();
+ JCommander.newBuilder()
+ .addObject(args)
+ .args(new String[]{"--mv", "from", "to"})
+ .build();
-class Args {
- @Parameter(names = ["-f", "--file"], description = "File to load. Can be specified multiple times.")
- List&lt;String&gt; file
-}
+ Assert.assertNotNull(args.mvParameters);
+ Assert.assertEquals(args.mvParameters.from, "from");
+ Assert.assertEquals(args.mvParameters.to, "to");
+}</code></pre>
+</div>
+</div>
+</div>
+</div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_multiple_option_names">11. Multiple option names</h2>
+<div class="sectionbody">
+<div class="paragraph">
+<p>You can specify more than one option name:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">@Parameter(names = { "-d", "--outputDirectory" }, description = "Directory")
+private String outputDirectory;</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>will allow both following syntaxes:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-bash" data-lang="bash">$ java Main -d /tmp
+$ java Main --outputDirectory /tmp</code></pre>
+</div>
+</div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_other_option_configurations">12. Other option configurations</h2>
+<div class="sectionbody">
+<div class="paragraph">
+<p>You can configure how options are looked up in a few different ways:</p>
+</div>
+<div class="ulist">
+<ul>
+<li>
+<p><code>JCommander#setCaseSensitiveOptions(boolean)</code>: specify whether options are case sensitive. If you call this method with <code>false</code>, then <code>"-param"</code> and <code>"-PARAM"</code> are considered equal.</p>
+</li>
+<li>
+<p><code>JCommander#setAllowAbbreviatedOptions(boolean)</code>: specify whether users can pass abbreviated options. If you call this method with <code>true</code> then users can pass <code>"-par"</code> to specify an option called <code>-param</code>. JCommander will throw a <code>ParameterException</code> if the abbreviated name is ambiguous.</p>
+</li>
+</ul>
+</div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_required_and_optional_parameters">13. Required and optional parameters</h2>
+<div class="sectionbody">
+<div class="paragraph">
+<p>If some of your parameters are mandatory, you can use the <code>required</code> attribute (which default to <code>false</code>):</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">@Parameter(names = "-host", required = true)
+private String host;</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>If this parameter is not specified, JCommander will throw an exception telling you which options are missing.</p>
+</div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_default_values">14. Default values</h2>
+<div class="sectionbody">
+<div class="paragraph">
+<p>The most common way to specify a default value for your parameters is to initialize the field at declaration time:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">private Integer logLevel = 3;</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>For more complicated cases, you might want to be able to reuse identical default values across several main classes or be able to specify these default values in a centralized location such as a <code>.properties</code> or an XML file. In this case, you can use an <code>IDefaultProvider</code>:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">public interface IDefaultProvider {
+ /**
+ * @param optionName The name of the option as specified in the names() attribute
+ * of the @Parameter option (e.g. "-file").
+ *
+ * @return the default value for this option.
+ */
+ String getDefaultValueFor(String optionName);
+}</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>By passing an implementation of this interface to your JCommander object, you can now control which default value will be used for your options. Note that the value returned by this method will then be passed to a string converter, if any is applicable, thereby allowing you to specify default values for any types you need.</p>
+</div>
+<div class="paragraph">
+<p>For example, here is a default provider that will assign a default value of 42 for all your parameters except <code>"-debug"</code>:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">private static final IDefaultProvider DEFAULT_PROVIDER = new IDefaultProvider() {
+ @Override
+ public String getDefaultValueFor(String optionName) {
+ return "-debug".equals(optionName) ? "false" : "42";
+ }
+};
-new Args().with {
- new JCommander(it, args)
- file.each { println "file: ${new File(it).name}" }
-}
-</pre>
+// ...
-<h2><a class="section" name="More_examples">More examples</a></h2>
+JCommander jc = JCommander.newBuilder()
+ .addObject(new Args())
+ .defaultProvider(DEFAULT_PROVIDER)
+ .build()</code></pre>
+</div>
+</div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_help_parameter">15. Help parameter</h2>
+<div class="sectionbody">
+<div class="paragraph">
+<p>If one of your parameters is used to display some help or usage, you need use the help attribute:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">@Parameter(names = "--help", help = true)
+private boolean help;</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>If you omit this boolean, JCommander will instead issue an error message when it tries to validate your command and it finds that you didn&#8217;t specify some of the required parameters.</p>
+</div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_more_complex_syntaxes_commands">16. More complex syntaxes (commands)</h2>
+<div class="sectionbody">
+<div class="paragraph">
+<p>Complex tools such as <code>git</code> or <code>svn</code> understand a whole set of commands, each of which with their own specific syntax:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-bash" data-lang="bash">$ git commit --amend -m "Bug fix"</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>Words such as <code>"commit"</code> above are called "commands" in JCommander, and you can specify them by creating one arg object per command:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">@Parameters(separators = "=", commandDescription = "Record changes to the repository")
+private class CommandCommit {
-TestNG uses JCommander to parse its own command line, here is <a href="http://github.com/cbeust/testng/blob/master/src/main/java/org/testng/CommandLineArgs.java">its definition file</a>.
+ @Parameter(description = "The list of files to commit")
+ private List&lt;String&gt; files;
-<h2><a class="section" name="Mailing_list">Mailing list</a></h2>
+ @Parameter(names = "--amend", description = "Amend")
+ private Boolean amend = false;
-Join the <a href="http://groups.google.com/group/jcommander">JCommander Google group</a> if you are interested in discussions about JCommander.
+ @Parameter(names = "--author")
+ private String author;
+}
-<h2><a class="section" name="Javadocs">Javadocs</a></h2>
+@Parameters(commandDescription = "Add file contents to the index")
+public class CommandAdd {
-The Javadocs for JCommander can be found <a href="apidocs/">here</a>.
+ @Parameter(description = "File patterns to add to the index")
+ private List&lt;String&gt; patterns;
-<h2><a class="section" name="License">License</a></h2>
+ @Parameter(names = "-i")
+ private Boolean interactive = false;
+}</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>Then you register these commands with your JCommander object. After the parsing phase, you call <code>getParsedCommand()</code> on your JCommander object, and based on the command that is returned, you know which arg object to inspect (you can still use a main arg object if you want to support options before the first command appears on the command line):</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">CommandMain cm = new CommandMain();
+CommandAdd add = new CommandAdd();
+CommandCommit commit = new CommandCommit();
+JCommander jc = JCommander.newBuilder()
+ .addObject(cm)
+ .addCommand("add", add);
+ .addCommand("commit", commit);
+ .build();
-JCommander is released under the <a
-href="https://github.com/cbeust/jcommander/blob/master/license.txt">Apache 2.0</a> license.
+jc.parse("-v", "commit", "--amend", "--author=cbeust", "A.java", "B.java");
-<h2><a class="section" name="Download">Download</a></h2>
+Assert.assertTrue(cm.verbose);
+Assert.assertEquals(jc.getParsedCommand(), "commit");
+Assert.assertTrue(commit.amend);
+Assert.assertEquals(commit.author, "cbeust");
+Assert.assertEquals(commit.files, Arrays.asList("A.java", "B.java"));</code></pre>
+</div>
+</div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_exception">17. Exception</h2>
+<div class="sectionbody">
+<div class="paragraph">
+<p>Whenever JCommander detects an error, it will throw a <code>ParameterException</code>. Note that this is a Runtime Exception, since your application is probably not initialized correctly at this point. Also, <code>ParameterException</code> contains the
+<code>JCommander</code> instance and you can also invoke <code>usage()</code> on it if you need to display some help.</p>
+</div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_usage">18. Usage</h2>
+<div class="sectionbody">
+<div class="paragraph">
+<p>You can invoke <code>usage()</code> on the JCommander instance that you used to parse your command line in order to generate a summary of all the options that your program understands:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-bash" data-lang="bash">Usage: &lt;main class&gt; [options]
+ Options:
+ -debug Debug mode (default: false)
+ -groups Comma-separated list of group names to be run
+ * -log, -verbose Level of verbosity (default: 1)
+ -long A long number (default: 0)</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>You can customize the name of your program by calling <code>setProgramName()</code> on your JCommander object. Options preceded by an asterisk are required.</p>
+</div>
+<div class="paragraph">
+<p>You can also specify the order in which each option should be displayed when calling <code>usage()</code> by setting the <code>order</code> attribute of the <code>@Parameter</code> annotation:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">class Parameters {
+ @Parameter(names = "--importantOption", order = 0)
+ private boolean a;
+
+ @Parameter(names = "--lessImportantOption", order = 3)
+ private boolean b;</code></pre>
+</div>
+</div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_hiding_parameters">19. Hiding parameters</h2>
+<div class="sectionbody">
+<div class="paragraph">
+<p>If you don&#8217;t want certain parameters to appear in the usage, you can mark them as "hidden":</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">@Parameter(names = "-debug", description = "Debug mode", hidden = true)
+private boolean debug = false;</code></pre>
+</div>
+</div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_internationalization">20. Internationalization</h2>
+<div class="sectionbody">
+<div class="paragraph">
+<p>You can internationalize the descriptions of your parameters. First you use the <code>@Parameters</code> annotation at the top of your class to define the name of your message bundle, and then you use the <code>descriptionKey</code> attribute instead of description on all the <code>@Parameters</code> that require translations. This <code>descriptionKey</code> is the key to the string into your message bundle:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">@Parameters(resourceBundle = "MessageBundle")
+private class ArgsI18N2 {
+ @Parameter(names = "-host", description = "Host", descriptionKey = "host")
+ String hostName;
+}</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>Your bundle needs to define this key:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-bash" data-lang="bash">host: Hôte</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>JCommander will then use the default locale to resolve your descriptions.</p>
+</div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_parameter_delegates">21. Parameter delegates</h2>
+<div class="sectionbody">
+<div class="paragraph">
+<p>If you are writing many different tools in the same project, you will probably find that most of these tools can share configurations. While you can use inheritance with your objects to avoid repeating this code, the restriction to single inheritance of implementation might limit your flexibility. To address this problem, JCommander supports parameter delegates.</p>
+</div>
+<div class="paragraph">
+<p>When JCommander encounters an object annotated with <code>@ParameterDelegate</code> in one of your objects, it acts as if this object had been added as a description object itself:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">class Delegate {
+ @Parameter(names = "-port")
+ private int port;
+}
-You can download JCommander from the following locations:
+class MainParams {
+ @Parameter(names = "-v")
+ private boolean verbose;
-<ul>
- <li><a href="http://github.com/cbeust/jcommander">Source on github</a></li>
- <li>If you are using Maven, add the following dependency to your <tt>pom.xml</tt>:
+ @ParametersDelegate
+ private Delegate delegate = new Delegate();
+}</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>The example above specifies a delegate parameter Delegate which is then referenced in MainParams. You only need to add a <code>MainParams</code> object to your
+JCommander configuration in order to use the delegate:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">MainParams p = new MainParams();
+JCommander.newBuilder().addObject(p).build()
+ .parse("-v", "-port", "1234");
+Assert.assertTrue(p.isVerbose);
+Assert.assertEquals(p.delegate.port, 1234);</code></pre>
+</div>
+</div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_dynamic_parameters">22. Dynamic parameters</h2>
+<div class="sectionbody">
+<div class="paragraph">
+<p>JCommander allows you to specify parameters that are not known at compile time, such as "-Da=b -Dc=d". Such parameters are specified with the <code>@DynamicParameter</code> annotation and must be of type <code>Map&lt;String, String&gt;</code>. Dynamic parameters are allowed to appear multiple times on the command line:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-java" data-lang="java">@DynamicParameter(names = "-D", description = "Dynamic parameters go here")
+private Map&lt;String, String&gt; params = new HashMap&lt;&gt;();</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>You can specify a different assignment string than = by using the attribute assignment.</p>
+</div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_jcommander_in_other_languages">23. JCommander in other languages</h2>
+<div class="sectionbody">
+<div class="sect2">
+<h3 id="_kotlin">23.1. Kotlin</h3>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-kotlin" data-lang="kotlin">class Args {
+ @Parameter
+ var targets: List&lt;String&gt; = arrayListOf()
+
+ @Parameter(names = arrayOf("-bf", "--buildFile"), description = "The build file")
+ var buildFile: String? = null
+
+ @Parameter(names = arrayOf("--checkVersions"),
+ description = "Check if there are any newer versions of the dependencies")
+ var checkVersions = false
+}</code></pre>
+</div>
+</div>
+</div>
+<div class="sect2">
+<h3 id="_groovy">23.2. Groovy</h3>
+<div class="paragraph">
+<p>Courtesy of Paul King:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-groovy" data-lang="groovy">import com.beust.jcommander.*
- <pre class="brush: xml">
+class Args {
+ @Parameter(names = ["-f", "--file"], description = "File to load. Can be specified multiple times.")
+ List&lt;String&gt; file
+}
-<dependency>
+new Args().with {
+ JCommander.newBuilder().addObject(it).build().parse(argv)
+ file.each { println "file: ${new File(it).name}" }
+}</code></pre>
+</div>
+</div>
+</div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_more_examples">24. More examples</h2>
+<div class="sectionbody">
+<div class="paragraph">
+<p>Here are the description files for a few projects that use JCommander:</p>
+</div>
+<div class="ulist">
+<ul>
+<li>
+<p><a href="https://github.com/cbeust/testng/blob/master/src/main/java/org/testng/CommandLineArgs.java">TestNG</a></p>
+</li>
+<li>
+<p><a href="https://github.com/cbeust/kobalt/blob/master/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Args.kt">Kobalt</a></p>
+</li>
+</ul>
+</div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_mailing_list">25. Mailing list</h2>
+<div class="sectionbody">
+<div class="paragraph">
+<p>Join the <a href="http://groups.google.com/group/jcommander">JCommander Google group</a> if you are interested in discussions about JCommander.</p>
+</div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_javadocs">26. Javadocs</h2>
+<div class="sectionbody">
+<div class="paragraph">
+<p>The Javadocs for JCommander can be found <a href="http://jcommander.org/apidocs/">here</a>.</p>
+</div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_license">27. License</h2>
+<div class="sectionbody">
+<div class="paragraph">
+<p>JCommander is released under the <a href="https://github.com/cbeust/jcommander/blob/master/license.txt">Apache 2.0 license</a>.</p>
+</div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_download">28. Download</h2>
+<div class="sectionbody">
+<div class="paragraph">
+<p>You can download JCommander from the following locations:</p>
+</div>
+<div class="ulist">
+<ul>
+<li>
+<p><a href="http://github.com/cbeust/jcommander">Source on github</a></p>
+</li>
+<li>
+<p>Kobalt</p>
+</li>
+</ul>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-groovy" data-lang="groovy">compile("com.beust:jcommander:1.71")</code></pre>
+</div>
+</div>
+<div class="ulist">
+<ul>
+<li>
+<p>Gradle</p>
+</li>
+</ul>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-groovy" data-lang="groovy">compile "com.beust:jcommander:1.71"</code></pre>
+</div>
+</div>
+<div class="ulist">
+<ul>
+<li>
+<p>Maven:</p>
+</li>
+</ul>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code class="language-xml" data-lang="xml">&lt;dependency&gt;
&lt;groupId&gt;com.beust&lt;/groupId&gt;
&lt;artifactId&gt;jcommander&lt;/artifactId&gt;
- &lt;version&gt;1.30&lt;/version&gt;
-</dependency>
- </pre>
-
-</ul>
-
+ &lt;version&gt;1.71&lt;/version&gt;
+&lt;/dependency&gt;</code></pre>
+</div>
+</div>
+</div>
+</div>
+</div>
+<div id="footer">
+<div id="footer-text">
+Last updated 2017-05-02 10:07:41 PDT
+</div>
+</div>
+<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prettify/r298/prettify.min.css">
+<script src="https://cdnjs.cloudflare.com/ajax/libs/prettify/r298/prettify.min.js"></script>
+<script>prettyPrint()</script>
</body>
-
-<script type="text/javascript" src="http://beust.com/toc.js"></script>
-<script type="text/javascript"> generateToc(); </script>
-
-</html>
+</html> \ No newline at end of file