Lines Matching +full:is +full:- +full:plain +full:- +full:object
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
5 <!--
7 -->
32 <h2>Because life is too short to parse command line parameters</h2>
34 <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
41 <input type="hidden" name="bn" value="PP-DonationsBF:btn_donate_LG.gif:NonHostedGuest">
42 …cts.com/en_US/i/btn/btn_donate_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier wa…
62 <div id="table-of-contents">
69 JCommander is a very small Java framework that makes it trivial to parse command line parameters.
80 @Parameter(names = { "-log", "-verbose" }, description = "Level of verbosity")
83 @Parameter(names = "-groups", description = "Comma-separated list of group names to be run")
86 @Parameter(names = "-debug", description = "Debug mode")
95 String[] argv = { "-log", "2", "-groups", "unit" };
106 @Parameter(names={"--length", "-l"})
108 @Parameter(names={"--pattern", "-p"})
123 If you were to run <code>java Main -l 512 --pattern 2</code>, this would
134 When a <tt>Parameter</tt> annotation is found on a field of type <tt>boolean</tt> or <tt>Boolean</t…
137 @Parameter(names = "-debug", description = "Debug mode")
148 @Parameter(names = "-debug", description = "Debug mode", arity = 1)
154 <pre class="brush: plain">
155 program -debug true
156 program -debug false
161 When a <tt>Parameter</tt> annotation is found on a field of type <tt>String</tt>, <tt>Integer</tt>,…
164 @Parameter(names = "-log", description = "Level of verbosity")
168 <pre class="brush: plain">
169 java Main -log 3
174 <pre class="brush: plain">
175 java Main -log test
182 When a <tt>Parameter</tt> annotation is found on a field of type <tt>List</tt>, JCommander will int…
185 @Parameter(names = "-host", description = "The host")
191 <pre class="brush: plain">
192 java Main -host host1 -verbose -host host2
195 When JCommander is done parsing the line above, the field <tt>hosts</tt> will contain the strings "…
199 If one of your parameters is a password or some other value that you do not wish to appear in your …
203 @Parameter(names = "-password", description = "Connection password", password = true)
210 <pre class="brush: plain">
211 Value for -password (Connection password):
218 …g <tt>echoInput</tt> to "true" (default is "false" and this setting only has an effect when <tt>pa…
221 …@Parameter(names = "-password", description = "Connection password", password = true, echoInput = …
238 For example, here is a converter that turns a string into a <tt>File</tt>:
249 Then, all you need to do is declare your field with the correct type and specify the converter as a…
252 @Parameter(names = "-file", converter = FileConverter.class)
270 <pre class="brush: plain">
271 java App -target example.com:8080
299 The factory is straightforward:
313 @Parameter(names = "-hostport")
319 All you need to do is add the factory to your JCommander object:
325 jc.parse("-hostport", "example.com:8080");
332 Another advantage of using string converter factories is that your factories can come from a depend…
362 * @param name The name of the parameter (e.g. "-host").
365 * @throws ParameterException Thrown if the value of the parameter is invalid.
372 Here is an example implementation that will make sure that the parameter is a positive integer:
389 @Parameter(names = "-age", validateWith = PositiveInteger.class)
401 JCommander does not provide any annotation-based solution to perform this validation because such
414 @Parameter(names = "-debug", description = "Debugging level")
420 <pre class="brush: plain">
421 java Main -debug file1 file2
432 @Parameter(names = "-verbose")
443 new JCommander(args, "-verbose", "3");
451 <pre class="brush: plain">
452 java Main -log:3
457 <pre class="brush: plain">
458 java Main -level=42
466 @Parameter(names = "-level")
485 @Parameter(names = "-master")
493 @Parameter(names = "-slave")
503 String[] argv = { "-master", "master", "-slave", "slave" };
504 new JCommander(new Object[] { m , s }, argv);
518 <pre class="brush: plain">
519 -verbose
524 <pre class="brush: plain">
528 <p>The file is read using the default charset unless <code>JCommander#setAtFileCharset</code> had b…
534 <h3><a class="section" name="fixed-arities" indent="..">Fixed arities</a></h3>
537 following example where two values are expected after <tt>-pairs</tt>:
539 <pre class="brush: plain">
540 java Main -pairs slave master foo.xml
547 @Parameter(names = "-pairs", arity = 2, description = "Pairs")
557 Also, note that only <tt>List<String></tt> is allowed for
560 other (this limitation is due to Java's erasure).
562 <h3><a class="section" name="variable-arities" indent="..">Variable arities</a></h3>
567 program -foo a1 a2 a3 -bar
568 program -foo a1 -bar
574 @Parameter(names = "-foo", variableArity = true)
584 @Parameter(names = { "-d", "--outputDirectory" }, description = "Directory")
591 <pre class="brush: plain">
592 java Main -d /tmp
593 java Main --outputDirectory /tmp
601 …options are case sensitive. If you call this method with <tt>false</tt>, then <tt>"-param"</tt> and
602 <tt>"-PARAM"</tt> are considered equal.
606 can pass <tt>"-par"</tt> to specify an option called <tt>-param</tt>. JCommander will
607 throw a <tt>ParameterException</tt> if the abbreviated name is ambiguous.
618 @Parameter(names = "-host", required = true)
623 If this parameter is not specified, JCommander will throw an exception
628 The most common way to specify a default value for your parameters is to initialize the field at de…
640 * of the @Parameter option (e.g. "-file").
648 …object, you can now control which default value will be used for your options. Note that the value…
652 For example, here is a default provider that will assign a default value of 42 for all your paramet…
658 return "-debug".equals(optionName) ? "false" : "42";
670 If one of your parameters is used to display some help or usage, you need use the <tt>help</tt> att…
673 @Parameter(names = "--help", help = true)
683 <pre class="brush: plain">
684 git commit --amend -m "Bug fix"
687 …e called "commands" in JCommander, and you can specify them by creating one arg object per command:
696 @Parameter(names = "--amend", description = "Amend")
699 @Parameter(names = "--author")
711 @Parameter(names = "-i")
716 …object. After the parsing phase, you call <tt>getParsedCommand()</tt> on your JCommander object, a…
727 jc.parse("-v", "commit", "--amend", "--author=cbeust", "A.java", "B.java");
739 <tt>ParameterException</tt>. Note that this is a Runtime Exception,
740 since your application is probably not initialized correctly at this
748 <pre class="brush: plain">
751 -debug Debug mode (default: false)
752 -groups Comma-separated list of group names to be run
753 * -log, -verbose Level of verbosity (default: 1)
754 -long A long number (default: 0)
757 …e the name of your program by calling <tt>setProgramName()</tt> on your <tt>JCommander</tt> object.
766 @Parameter(names = "-debug", description = "Debug mode", hidden = true)
776 …t>@Parameters</tt> that require translations. This <tt>descriptionKey</tt> is the key to the strin…
782 @Parameter(names = "-host", description = "Host", descriptionKey = "host")
792 <pre class="brush: plain">
804 …ers an object annotated with <tt>@ParameterDelegate</tt> in one of your objects, it acts as if thi…
808 @Parameter(names = "-port")
813 @Parameter(names = "-v")
821 …meter <tt>Delegate</tt> which is then referenced in <tt>MainParams</tt>. You only need to add a <t…
825 new JCommander(p).parse("-v", "-port", "1234");
832 …u to specify parameters that are not known at compile time, such as <tt>"-Da=b -Dc=d"</tt>. Such p…
835 @DynamicParameter(names = "-D", description = "Dynamic parameters go here")
843 Here is a quick example of how to use JCommander in Scala (courtesy of Patrick Linskey):
850 object Main {
851 object Args {
857 names = Array("-f", "--file"),
864 for (filename <- Args.file) {
874 Here is a quick example of how to use JCommander in Groovy (courtesy of Paul King):
881 …@Parameter(names = ["-f", "--file"], description = "File to load. Can be specified multiple times.…
893 TestNG uses JCommander to parse its own command line, here is <a href="http://github.com/cbeust/tes…
905 JCommander is released under the <a
916 <pre class="brush: plain">