diff options
author | Cedric Beust <cedric@beust.com> | 2011-06-29 16:30:32 -0700 |
---|---|---|
committer | Cedric Beust <cedric@beust.com> | 2011-06-29 16:30:32 -0700 |
commit | 1f80e8ab0d32fdd23634e76b780a4ca6487ee42b (patch) | |
tree | bd7e3dd0901531eb08a3f182c3fe88cbd0ec41c7 /doc | |
parent | 32868be31e1c6fd5b55608c05dc3eab3d0295239 (diff) | |
download | platform_external_jcommander-1f80e8ab0d32fdd23634e76b780a4ca6487ee42b.tar.gz platform_external_jcommander-1f80e8ab0d32fdd23634e76b780a4ca6487ee42b.tar.bz2 platform_external_jcommander-1f80e8ab0d32fdd23634e76b780a4ca6487ee42b.zip |
Scala doc update.
Diffstat (limited to 'doc')
-rw-r--r-- | doc/index.html | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/doc/index.html b/doc/index.html index 3246ba3..21ffb09 100644 --- a/doc/index.html +++ b/doc/index.html @@ -600,6 +600,37 @@ host: Hôte JCommander will then use the default locale to resolve your descriptions. +<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): + +<pre class="brush: java"> +import java.io.File +import com.beust.jcommander.{JCommander, Parameter} +import collection.JavaConversions._ + +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 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 + } + + 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) + } + } +} +</pre> + <h2><a class="section" name="More_examples">More examples</a></h2> TestNG uses JCommander to parse its command line, here is <a href="http://github.com/cbeust/testng/blob/master/src/main/java/org/testng/CommandLineArgs.java">its definition file</a>. |