summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorCedric Beust <cedric@beust.com>2011-11-25 09:17:47 -0800
committerCedric Beust <cedric@beust.com>2011-11-25 09:17:47 -0800
commitb871944ccc7f31a310f0d6b2e1568ac6656f2bec (patch)
treec63037bdddc36927e3d6c2d1907dfe3f67905a56 /doc
parentc211263cd41868d1bd2e1f452a75f2504e853501 (diff)
downloadjcommander-b871944ccc7f31a310f0d6b2e1568ac6656f2bec.tar.gz
ParametersDelegate: doc and some minor formatting.
Diffstat (limited to 'doc')
-rw-r--r--doc/index.html32
1 files changed, 32 insertions, 0 deletions
diff --git a/doc/index.html b/doc/index.html
index 56b681e..3482063 100644
--- a/doc/index.html
+++ b/doc/index.html
@@ -644,6 +644,38 @@ host: H&ocirc;te
JCommander will then use the default locale to resolve your descriptions.
+<h2><a class="section" name="ParameterDeletages">Parameter delegates</a></h2>
+
+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>
+
+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:
+
+<pre class="brush: java">
+class Delegate {
+ @Parameter(names = "-port")
+ public int port;
+}
+
+class MainParams {
+ @Parameter(names = "-v")
+ public boolean verbose;
+
+ @ParametersDelegate
+ public Delegate delegate = new Delegate();
+}
+</pre>
+
+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:
+
+<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>
+
<h2><a class="section" name="Scala">JCommander in Scala</a></h2>
Here is a quick example of how to use JCommander in Scala (courtesy of Patrick Linskey):