Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X 3c0b7e871 -> 6abd51d3a


some minimal CliBuilder doco


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/6abd51d3
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/6abd51d3
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/6abd51d3

Branch: refs/heads/GROOVY_2_4_X
Commit: 6abd51d3a011892b593d5ca669519bb846579e36
Parents: 3c0b7e8
Author: paulk <pa...@asert.com.au>
Authored: Fri Mar 25 09:15:39 2016 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Fri Mar 25 09:16:22 2016 +1000

----------------------------------------------------------------------
 .../doc/core-domain-specific-languages.adoc     | 66 +++++++++++++++++++-
 1 file changed, 65 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/6abd51d3/src/spec/doc/core-domain-specific-languages.adoc
----------------------------------------------------------------------
diff --git a/src/spec/doc/core-domain-specific-languages.adoc 
b/src/spec/doc/core-domain-specific-languages.adoc
index d733a09..6c0b16d 100644
--- a/src/spec/doc/core-domain-specific-languages.adoc
+++ b/src/spec/doc/core-domain-specific-languages.adoc
@@ -1083,8 +1083,72 @@ 
include::{projectdir}/subprojects/groovy-ant/{specfolder}/ant-builder.adoc[level
 
 ==== CliBuilder
 
-(TBD)
+`CliBuilder` provides a compact way to specify the available parameters for a 
command-line application and then
+automatically parse the application's parameters according to that 
specification. Here is a simple example
+`Greeter.groovy` script illustrating usage:
+
+[source,groovy]
+---------------------------
+// specify parameters
+def cli = new CliBuilder(usage: 'groovy Greeter [option]') <1>
+cli.a(longOpt: 'audience', args: 1, 'greeting audience')   <2>
+cli.h(longOpt: 'help', 'display usage')                    <3>
+
+// parse and process parameters
+def options = cli.parse(args)                              <4>
+if (options.h) cli.usage()                                 <5>
+else println "Hello ${options.a ? options.a : 'World'}"    <6>
+---------------------------
+<1> define a new `CliBuilder` instance specifying an optional usage string
+<2> specify a `-a` parameter taking a single argument with an optional long 
variant `--audience`
+<3> specify a `-h` parameter taking no arguments with an optional long variant 
`--help`
+<4> parse the arguments supplied to the script
+<5> if the `h` argument is found display a usage message
+<6> display a standard greeting or if the `a` argument is found a customized 
greeting
+
+Running this script with no arguments, i.e.:
+
+[source,shell]
+----
+> groovy Greeter
+----
+
+results in the following output:
+
+[source,shell]
+----
+Hello World
+----
+
+Running this script with `-h` as the arguments, i.e.:
 
+[source,shell]
+----
+> groovy Greeter -h
+----
+
+results in the following output:
+
+[source,shell]
+----
+usage: groovy Greeter [option]
+ -a,--audience <arg>   greeting audience
+ -h,--help             display usage
+----
+
+Running this script with `--audience Groovologist` as the arguments, i.e.:
+
+[source,shell]
+----
+> groovy Greeter --audience Groovologist
+----
+
+results in the following output:
+
+[source,shell]
+----
+Hello Groovologist
+----
 
 ==== ObjectGraphBuilder
 

Reply via email to