Skip to content

Commit 5db7cc6

Browse files
author
Robert James Oxspring
committed
Documented ant example
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/cli/trunk@130115 13f79535-47bb-0310-9956-ffa450edef68
1 parent fe5fd7e commit 5db7cc6

2 files changed

Lines changed: 323 additions & 5 deletions

File tree

src/test/org/apache/commons/cli2/DocumentationTest.java

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import java.io.IOException;
1919
import java.io.PrintWriter;
2020
import java.io.StringWriter;
21+
import java.util.Iterator;
22+
import java.util.List;
2123

2224
import junit.framework.TestCase;
2325

@@ -147,8 +149,8 @@ public void testBasicUsage() throws IOException, OptionException {
147149
}
148150
}
149151

150-
public void testExampleAnt() throws IOException {
151-
// Based on Ant 1.5.3
152+
public void testExampleAnt() throws IOException, OptionException {
153+
// Apache Ant version 1.6.1 compiled on February 12 2004
152154

153155
final DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
154156
final ArgumentBuilder abuilder = new ArgumentBuilder();
@@ -157,11 +159,13 @@ public void testExampleAnt() throws IOException {
157159
Option help =
158160
obuilder
159161
.withShortName("help")
162+
.withShortName("h")
160163
.withDescription("print this message")
161164
.create();
162165
Option projecthelp =
163166
obuilder
164167
.withShortName("projecthelp")
168+
.withShortName("p")
165169
.withDescription("print project help information")
166170
.create();
167171
Option version =
@@ -189,18 +193,31 @@ public void testExampleAnt() throws IOException {
189193
Option debug =
190194
obuilder
191195
.withShortName("debug")
196+
.withShortName("d")
192197
.withDescription("print debugging information")
193198
.create();
194199
Option emacs =
195200
obuilder
196201
.withShortName("emacs")
202+
.withShortName("e")
197203
.withDescription("produce logging information without adornments")
198204
.create();
205+
Option lib =
206+
obuilder
207+
.withShortName("lib")
208+
.withDescription("specifies a path to search for jars and classes")
209+
.withArgument(
210+
abuilder
211+
.withName("path")
212+
.withMinimum(1)
213+
.withMaximum(1)
214+
.create())
215+
.create();
199216
Option logfile =
200217
obuilder
201218
.withShortName("logfile")
202219
.withShortName("l")
203-
.withDescription("produce logging information without adornments")
220+
.withDescription("use given file for log")
204221
.withArgument(
205222
abuilder
206223
.withName("file")
@@ -230,11 +247,16 @@ public void testExampleAnt() throws IOException {
230247
.withMaximum(1)
231248
.create())
232249
.create();
250+
Option noinput =
251+
obuilder
252+
.withShortName("noinput")
253+
.withDescription("do not allow interactive input")
254+
.create();
233255
Option buildfile =
234256
obuilder
235257
.withShortName("buildfile")
236-
.withShortName("b")
237258
.withShortName("file")
259+
.withShortName("f")
238260
.withDescription("use given buildfile")
239261
.withArgument(
240262
abuilder
@@ -269,6 +291,7 @@ public void testExampleAnt() throws IOException {
269291
Option find =
270292
obuilder
271293
.withShortName("find")
294+
.withShortName("s")
272295
.withDescription("search for buildfile towards the root of the filesystem and use it")
273296
.withArgument(
274297
abuilder
@@ -290,16 +313,45 @@ public void testExampleAnt() throws IOException {
290313
.withOption(verbose)
291314
.withOption(debug)
292315
.withOption(emacs)
316+
.withOption(lib)
293317
.withOption(logfile)
294318
.withOption(logger)
295319
.withOption(listener)
320+
.withOption(noinput)
296321
.withOption(buildfile)
297322
.withOption(property)
298323
.withOption(propertyfile)
299324
.withOption(inputhandler)
300325
.withOption(find)
301326
.withOption(targets)
302327
.create();
328+
329+
/////////////////////////////////////
330+
String[] args = new String[]{};
331+
332+
Parser parser = new Parser();
333+
parser.setGroup(options);
334+
CommandLine cl = parser.parse(args);
335+
336+
if(cl.hasOption(help)) {
337+
//displayHelp();
338+
return;
339+
}
340+
if(cl.hasOption("-version")) {
341+
//displayVersion();
342+
return;
343+
}
344+
if(cl.hasOption(logfile)) {
345+
String file = (String)cl.getValue(logfile);
346+
//setLogFile();
347+
}
348+
List targetList = cl.getValues(targets);
349+
for (Iterator i = targetList.iterator(); i.hasNext();) {
350+
String target = (String) i.next();
351+
//doTarget(target);
352+
}
353+
354+
/////////////////////////////////////
303355

304356
HelpFormatter hf = new HelpFormatter();
305357
hf.setShellCommand("ant");
@@ -309,6 +361,7 @@ public void testExampleAnt() throws IOException {
309361

310362
hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_PROPERTY_OPTION);
311363
hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_PARENT_ARGUMENT);
364+
hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_ARGUMENT_BRACKETED);
312365

313366
hf.getDisplaySettings().remove(DisplaySetting.DISPLAY_GROUP_ARGUMENT);
314367

0 commit comments

Comments
 (0)