commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r639941 [8/17] - in /commons/proper/cli/trunk: ./ src/java/org/apache/commons/cli2/ src/java/org/apache/commons/cli2/builder/ src/java/org/apache/commons/cli2/commandline/ src/java/org/apache/commons/cli2/option/ src/java/org/apache/commons...
Date Sat, 22 Mar 2008 02:49:46 GMT
Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli2/CommandLineDefaultsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/CommandLineDefaultsTest.java?rev=639941&r1=639940&r2=639941&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli2/CommandLineDefaultsTest.java (original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli2/CommandLineDefaultsTest.java Fri Mar 21 19:49:41 2008
@@ -1,251 +1 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.cli2;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.apache.commons.cli2.builder.ArgumentBuilder;
-import org.apache.commons.cli2.builder.SwitchBuilder;
-import org.apache.commons.cli2.commandline.WriteableCommandLineImpl;
-
-/**
- * Tests the interaction of command line values and defaults supplied in different ways.
- * 
- * Tests marked _Parsed involve values parsed from a command line.
- * 
- * Tests marked _Method involve defaults supplied in the query method.
- * 
- * Tests marked _Option involce defaults specified in the model.
- * 
- * @author Rob Oxspring
- */
-public class CommandLineDefaultsTest extends TestCase {
-    
-    /*
-     * utils to grab the default from the method 
-     */
-    
-    private Object methodSwitch(WriteableCommandLine cl, Option o, Boolean bool) {
-        return cl.getSwitch(o, bool);
-    }
-
-    private Object methodSwitchNull(WriteableCommandLine cl, Option o) {
-        return methodSwitch(cl, o, null);
-    }
-
-    private Object methodSwitchOff(WriteableCommandLine cl, Option o) {
-        return methodSwitch(cl, o, Boolean.FALSE);
-    }
-
-    private Object methodSwitchOn(WriteableCommandLine cl, Option o) {
-        return methodSwitch(cl, o, Boolean.TRUE);
-    }
-
-    private Object methodValueMissing(WriteableCommandLine cl, Option o) {
-        return cl.getValue(o);
-    }
-
-    private Object methodValuePresent(WriteableCommandLine cl, Option o) {
-        return cl.getValue(o, "method");
-    }
-
-    /*
-     * utils to grab the default from the option model 
-     */
-    
-    private Option optionSwitch(Boolean bool) {
-        return new SwitchBuilder().withName("switch").withSwitchDefault(bool)
-                .create();
-    }
-
-    private Option optionSwitchNull() {
-        return optionSwitch(null);
-    }
-
-    private Option optionSwitchOff() {
-        return optionSwitch(Boolean.FALSE);
-    }
-
-    private Option optionSwitchOn() {
-        return optionSwitch(Boolean.TRUE);
-    }
-
-    private Option optionValueMissing() {
-        return new ArgumentBuilder().create();
-    }
-
-    private Option optionValuePresent() {
-        return new ArgumentBuilder().withDefaults(
-                Arrays.asList(new String[] { "option" })).create();
-    }
-
-    /*
-     * utils to grab the input from the command line 
-     */
-    
-    private WriteableCommandLine parsedSwitch(Option o, Boolean bool) {
-        final List args;
-        if (bool == null) {
-            args = Collections.EMPTY_LIST;
-        } else {
-            args = Collections
-                    .singletonList(String.valueOf(bool).toLowerCase());
-        }
-        WriteableCommandLine cl = new WriteableCommandLineImpl(o, args);
-        o.defaults(cl);
-        if (bool != null) {
-            cl.addSwitch(o, bool.booleanValue());
-        }
-        return cl;
-    }
-
-    private WriteableCommandLine parsedSwitchNull(Option o) {
-        return parsedSwitch(o, null);
-    }
-
-    private WriteableCommandLine parsedSwitchOn(Option o) {
-        return parsedSwitch(o, Boolean.TRUE);
-    }
-
-    private WriteableCommandLine parsedValueMissing(Option o) {
-        WriteableCommandLine cl = new WriteableCommandLineImpl(o,
-                Collections.EMPTY_LIST);
-        o.defaults(cl);
-        return cl;
-    }
-
-    private WriteableCommandLine parsedValuePresent(Option o) {
-        WriteableCommandLine cl = new WriteableCommandLineImpl(o, Arrays
-                .asList(new String[] { "parsed" }));
-        o.defaults(cl);
-        cl.addValue(o, "parsed");
-        return cl;
-    }
-    
-    /*
-     * tests
-     */
-
-    public void testSwitch_Method() {
-        final Option o = optionSwitchNull();
-        final WriteableCommandLine cl = parsedSwitchNull(o);
-        final Object v = methodSwitchOn(cl, o);
-        assertEquals(Boolean.TRUE, v);
-    }
-
-    public void testSwitch_Method_Option() {
-        final Option o = optionSwitchOff();
-        final WriteableCommandLine cl = parsedSwitchNull(o);
-        final Object v = methodSwitchOn(cl, o);
-        assertEquals(Boolean.TRUE, v);
-    }
-
-    public void testSwitch_Option() {
-        final Option o = optionSwitchOn();
-        final WriteableCommandLine cl = parsedSwitchNull(o);
-        final Object v = methodSwitchNull(cl, o);
-        assertEquals(Boolean.TRUE, v);
-    }
-
-    public void testSwitch_Parsed() {
-        final Option o = optionSwitchNull();
-        final WriteableCommandLine cl = parsedSwitchOn(o);
-        final Object v = methodSwitchNull(cl, o);
-        assertEquals(Boolean.TRUE, v);
-    }
-
-    public void testSwitch_Parsed_Method() {
-        final Option o = optionSwitchOff();
-        final WriteableCommandLine cl = parsedSwitchOn(o);
-        final Object v = methodSwitchNull(cl, o);
-        assertEquals(Boolean.TRUE, v);
-    }
-
-    public void testSwitch_Parsed_Method_Option() {
-        final Option o = optionSwitchOff();
-        final WriteableCommandLine cl = parsedSwitchOn(o);
-        final Object v = methodSwitchOff(cl, o);
-        assertEquals(Boolean.TRUE, v);
-    }
-
-    public void testSwitch_Parsed_Option() {
-        final Option o = optionSwitchOff();
-        final WriteableCommandLine cl = parsedSwitchOn(o);
-        final Object v = methodSwitchNull(cl, o);
-        assertEquals(Boolean.TRUE, v);
-    }
-
-    public void testValues() {
-        final Option o = optionValueMissing();
-        final WriteableCommandLine cl = parsedValueMissing(o);
-        final Object v = methodValueMissing(cl, o);
-        assertNull(v);
-    }
-
-    public void testValues_Method() {
-        final Option o = optionValueMissing();
-        final WriteableCommandLine cl = parsedValueMissing(o);
-        final Object v = methodValuePresent(cl, o);
-        assertEquals("method", v);
-    }
-
-    public void testValues_Method_Option() {
-        final Option o = optionValuePresent();
-        final WriteableCommandLine cl = parsedValueMissing(o);
-        final Object v = methodValuePresent(cl, o);
-        assertEquals("method", v);
-    }
-
-    public void testValues_Option() {
-        final Option o = optionValuePresent();
-        final WriteableCommandLine cl = parsedValueMissing(o);
-        final Object v = methodValueMissing(cl, o);
-        assertEquals("option", v);
-    }
-
-    public void testValues_Parsed() {
-        final Option o = optionValueMissing();
-        final WriteableCommandLine cl = parsedValuePresent(o);
-        final Object v = methodValueMissing(cl, o);
-        assertEquals("parsed", v);
-    }
-
-    public void testValues_Parsed_Method() {
-        final Option o = optionValueMissing();
-        final WriteableCommandLine cl = parsedValuePresent(o);
-        final Object v = methodValuePresent(cl, o);
-        assertEquals("parsed", v);
-    }
-
-    public void testValues_Parsed_Method_Option() {
-        final Option o = optionValuePresent();
-        final WriteableCommandLine cl = parsedValuePresent(o);
-        final Object v = methodValuePresent(cl, o);
-        assertEquals("parsed", v);
-    }
-
-    public void testValues_Parsed_Option() {
-        final Option o = optionValuePresent();
-        final WriteableCommandLine cl = parsedValuePresent(o);
-        final Object v = methodValueMissing(cl, o);
-        assertEquals("parsed", v);
-    }
-}
\ No newline at end of file
+/** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements.  See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License.  You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.commons.cli2;import java.util.Arrays;import java.util.Collections;import java.util.List;import junit.framework.TestCase;import org.apache.commons.cli2.builder.ArgumentBuilder;import o
 rg.apache.commons.cli2.builder.SwitchBuilder;import org.apache.commons.cli2.commandline.WriteableCommandLineImpl;/** * Tests the interaction of command line values and defaults supplied in different ways. * * Tests marked _Parsed involve values parsed from a command line. * * Tests marked _Method involve defaults supplied in the query method. * * Tests marked _Option involce defaults specified in the model. * * @author Rob Oxspring */public class CommandLineDefaultsTest extends TestCase {    /*     * utils to grab the default from the method     */    private Object methodSwitch(WriteableCommandLine cl, Option o, Boolean bool) {        return cl.getSwitch(o, bool);    }    private Object methodSwitchNull(WriteableCommandLine cl, Option o) {        return methodSwitch(cl, o, null);    }    private Object methodSwitchOff(WriteableCommandLine cl, Option o) {        return methodSwitch(cl, o, Boolean.FALSE);    }    private Object methodSwitchOn(WriteableCommandLine cl, Option o
 ) {        return methodSwitch(cl, o, Boolean.TRUE);    }    private Object methodValueMissing(WriteableCommandLine cl, Option o) {        return cl.getValue(o);    }    private Object methodValuePresent(WriteableCommandLine cl, Option o) {        return cl.getValue(o, "method");    }    /*     * utils to grab the default from the option model     */    private Option optionSwitch(Boolean bool) {        return new SwitchBuilder().withName("switch").withSwitchDefault(bool)                .create();    }    private Option optionSwitchNull() {        return optionSwitch(null);    }    private Option optionSwitchOff() {        return optionSwitch(Boolean.FALSE);    }    private Option optionSwitchOn() {        return optionSwitch(Boolean.TRUE);    }    private Option optionValueMissing() {        return new ArgumentBuilder().create();    }    private Option optionValuePresent() {        return new ArgumentBuilder().withDefaults(                Arrays.asList(new String[] { "optio
 n" })).create();    }    /*     * utils to grab the input from the command line     */    private WriteableCommandLine parsedSwitch(Option o, Boolean bool) {        final List args;        if (bool == null) {            args = Collections.EMPTY_LIST;        } else {            args = Collections                    .singletonList(String.valueOf(bool).toLowerCase());        }        WriteableCommandLine cl = new WriteableCommandLineImpl(o, args);        o.defaults(cl);        if (bool != null) {            cl.addSwitch(o, bool.booleanValue());        }        return cl;    }    private WriteableCommandLine parsedSwitchNull(Option o) {        return parsedSwitch(o, null);    }    private WriteableCommandLine parsedSwitchOn(Option o) {        return parsedSwitch(o, Boolean.TRUE);    }    private WriteableCommandLine parsedValueMissing(Option o) {        WriteableCommandLine cl = new WriteableCommandLineImpl(o,                Collections.EMPTY_LIST);        o.defaults(cl);       
  return cl;    }    private WriteableCommandLine parsedValuePresent(Option o) {        WriteableCommandLine cl = new WriteableCommandLineImpl(o, Arrays                .asList(new String[] { "parsed" }));        o.defaults(cl);        cl.addValue(o, "parsed");        return cl;    }    /*     * tests     */    public void testSwitch_Method() {        final Option o = optionSwitchNull();        final WriteableCommandLine cl = parsedSwitchNull(o);        final Object v = methodSwitchOn(cl, o);        assertEquals(Boolean.TRUE, v);    }    public void testSwitch_Method_Option() {        final Option o = optionSwitchOff();        final WriteableCommandLine cl = parsedSwitchNull(o);        final Object v = methodSwitchOn(cl, o);        assertEquals(Boolean.TRUE, v);    }    public void testSwitch_Option() {        final Option o = optionSwitchOn();        final WriteableCommandLine cl = parsedSwitchNull(o);        final Object v = methodSwitchNull(cl, o);        assertEquals(Boole
 an.TRUE, v);    }    public void testSwitch_Parsed() {        final Option o = optionSwitchNull();        final WriteableCommandLine cl = parsedSwitchOn(o);        final Object v = methodSwitchNull(cl, o);        assertEquals(Boolean.TRUE, v);    }    public void testSwitch_Parsed_Method() {        final Option o = optionSwitchOff();        final WriteableCommandLine cl = parsedSwitchOn(o);        final Object v = methodSwitchNull(cl, o);        assertEquals(Boolean.TRUE, v);    }    public void testSwitch_Parsed_Method_Option() {        final Option o = optionSwitchOff();        final WriteableCommandLine cl = parsedSwitchOn(o);        final Object v = methodSwitchOff(cl, o);        assertEquals(Boolean.TRUE, v);    }    public void testSwitch_Parsed_Option() {        final Option o = optionSwitchOff();        final WriteableCommandLine cl = parsedSwitchOn(o);        final Object v = methodSwitchNull(cl, o);        assertEquals(Boolean.TRUE, v);    }    public void testValu
 es() {        final Option o = optionValueMissing();        final WriteableCommandLine cl = parsedValueMissing(o);        final Object v = methodValueMissing(cl, o);        assertNull(v);    }    public void testValues_Method() {        final Option o = optionValueMissing();        final WriteableCommandLine cl = parsedValueMissing(o);        final Object v = methodValuePresent(cl, o);        assertEquals("method", v);    }    public void testValues_Method_Option() {        final Option o = optionValuePresent();        final WriteableCommandLine cl = parsedValueMissing(o);        final Object v = methodValuePresent(cl, o);        assertEquals("method", v);    }    public void testValues_Option() {        final Option o = optionValuePresent();        final WriteableCommandLine cl = parsedValueMissing(o);        final Object v = methodValueMissing(cl, o);        assertEquals("option", v);    }    public void testValues_Parsed() {        final Option o = optionValueMissing();  
       final WriteableCommandLine cl = parsedValuePresent(o);        final Object v = methodValueMissing(cl, o);        assertEquals("parsed", v);    }    public void testValues_Parsed_Method() {        final Option o = optionValueMissing();        final WriteableCommandLine cl = parsedValuePresent(o);        final Object v = methodValuePresent(cl, o);        assertEquals("parsed", v);    }    public void testValues_Parsed_Method_Option() {        final Option o = optionValuePresent();        final WriteableCommandLine cl = parsedValuePresent(o);        final Object v = methodValuePresent(cl, o);        assertEquals("parsed", v);    }    public void testValues_Parsed_Option() {        final Option o = optionValuePresent();        final WriteableCommandLine cl = parsedValuePresent(o);        final Object v = methodValueMissing(cl, o);        assertEquals("parsed", v);    }}
\ No newline at end of file

Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli2/CommandLineTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/CommandLineTestCase.java?rev=639941&r1=639940&r2=639941&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli2/CommandLineTestCase.java (original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli2/CommandLineTestCase.java Fri Mar 21 19:49:41 2008
@@ -1,512 +1 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.cli2;
-
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.commons.cli2.builder.ArgumentBuilder;
-import org.apache.commons.cli2.builder.DefaultOptionBuilder;
-import org.apache.commons.cli2.builder.GroupBuilder;
-import org.apache.commons.cli2.commandline.Parser;
-import org.apache.commons.cli2.option.ArgumentTest;
-import org.apache.commons.cli2.option.CommandTest;
-import org.apache.commons.cli2.option.DefaultOptionTest;
-import org.apache.commons.cli2.option.OptionTestCase;
-import org.apache.commons.cli2.option.PropertyOption;
-import org.apache.commons.cli2.option.SwitchTest;
-import org.apache.commons.cli2.resource.ResourceConstants;
-import org.apache.commons.cli2.resource.ResourceHelper;
-
-public abstract class CommandLineTestCase
-    extends CLITestCase {
-    private static final ResourceHelper resources = ResourceHelper.getResourceHelper();
-    public final Option present =
-        new DefaultOptionBuilder().withLongName("present").withLongName("alsopresent").create();
-    public final Option missing = new DefaultOptionBuilder().withLongName("missing").create();
-    public final Option multiple = new DefaultOptionBuilder().withLongName("multiple").create();
-    public final Option bool = new DefaultOptionBuilder().withLongName("bool").create();
-    public final Option root =
-        new GroupBuilder().withOption(present).withOption(missing).withOption(multiple)
-                          .withOption(bool).create();
-    private CommandLine commandLine;
-
-    protected abstract CommandLine createCommandLine();
-
-    /*
-     * @see TestCase#setUp()
-     */
-    public void setUp()
-        throws Exception {
-        super.setUp();
-        commandLine = createCommandLine();
-    }
-
-    /*
-     * Class to test for boolean hasOption(String)
-     */
-    public final void testHasOptionString() {
-        assertTrue(commandLine.hasOption("--present"));
-        assertTrue(commandLine.hasOption("--alsopresent"));
-        assertFalse(commandLine.hasOption("--missing"));
-    }
-
-    /*
-     * Class to test for boolean hasOption(Option)
-     */
-    public final void testHasOptionOption() {
-        assertTrue(commandLine.hasOption(present));
-        assertFalse(commandLine.hasOption(missing));
-    }
-
-    public final void testGetOption() {
-        assertSame(present, commandLine.getOption("--present"));
-        assertSame(present, commandLine.getOption("--alsopresent"));
-
-        //TODO decide whether the following assertion is valid
-        //assertSame(missing,commandLine.getOption("--missing"));
-    }
-
-    /*
-     * Class to test for List getValues(String)
-     */
-    public final void testGetValuesString() {
-        assertListContentsEqual(list("present value"), commandLine.getValues("--present"));
-        assertListContentsEqual(list("value 1", "value 2", "value 3"),
-                                commandLine.getValues("--multiple"));
-        assertTrue(commandLine.getValues("--missing").isEmpty());
-    }
-
-    /*
-     * Class to test for List getValues(String, List)
-     */
-    public final void testGetValuesStringList() {
-        assertListContentsEqual(list("present value"), commandLine.getValues("--present", null));
-        assertListContentsEqual(list("present value"), commandLine.getValues("--alsopresent", null));
-        assertSame(commandLine.getValues("--missing", Collections.EMPTY_LIST),
-                   Collections.EMPTY_LIST);
-
-        final List def = Collections.singletonList("default value");
-        assertSame(def, commandLine.getValues("--missing", def));
-    }
-
-    /*
-     * Class to test for List getValues(Option)
-     */
-    public final void testGetValuesOption() {
-        assertListContentsEqual(list("present value"), commandLine.getValues(present));
-        assertTrue(commandLine.getValues(missing).isEmpty());
-    }
-
-    /*
-     * Class to test for List getValues(Option, List)
-     */
-    public final void testGetValuesOptionList() {
-        assertListContentsEqual(list("present value"), commandLine.getValues(present));
-        assertSame(commandLine.getValues(missing, Collections.EMPTY_LIST), Collections.EMPTY_LIST);
-
-        final List defs = Collections.singletonList("custom default");
-        assertSame(defs, commandLine.getValues(missing, defs));
-    }
-
-    /*
-     * Class to test for Object getValue(String)
-     */
-    public final void testGetValueString() {
-        assertEquals("present value", commandLine.getValue("--present"));
-        assertEquals("present value", commandLine.getValue("--alsopresent"));
-        assertNull(commandLine.getValue("--missing"));
-
-        try {
-            commandLine.getValue("--multiple");
-            fail("expected IllegalStateException");
-        } catch (IllegalStateException e) {
-            assertEquals(resources.getMessage(ResourceConstants.ARGUMENT_TOO_MANY_VALUES),
-                         e.getMessage());
-        }
-    }
-
-    /*
-     * Class to test for Object getValue(String, Object)
-     */
-    public final void testGetValueStringObject() {
-        assertEquals("present value", commandLine.getValue("--present", "default value"));
-        assertEquals("present value", commandLine.getValue("--alsopresent", "default value"));
-        assertEquals("default value", commandLine.getValue("--missing", "default value"));
-
-        try {
-            commandLine.getValue("--multiple");
-            fail("expected IllegalStateException");
-        } catch (IllegalStateException e) {
-            assertEquals(resources.getMessage(ResourceConstants.ARGUMENT_TOO_MANY_VALUES),
-                         e.getMessage());
-        }
-    }
-
-    /*
-     * Class to test for Object getValue(Option)
-     */
-    public final void testGetValueOption() {
-        assertEquals("present value", commandLine.getValue(present));
-        assertNull(commandLine.getValue(missing));
-
-        try {
-            commandLine.getValue(multiple);
-            fail("expected IllegalStateException");
-        } catch (IllegalStateException e) {
-            assertEquals(resources.getMessage(ResourceConstants.ARGUMENT_TOO_MANY_VALUES),
-                         e.getMessage());
-        }
-    }
-
-    /*
-     * Class to test for Object getValue(Option, Object)
-     */
-    public final void testGetValueOptionObject() {
-        assertEquals("present value", commandLine.getValue(present, "default value"));
-        assertEquals("default value", commandLine.getValue(missing, "default value"));
-
-        try {
-            commandLine.getValue(multiple);
-            fail("expected IllegalStateException");
-        } catch (IllegalStateException e) {
-            assertEquals(resources.getMessage(ResourceConstants.ARGUMENT_TOO_MANY_VALUES),
-                         e.getMessage());
-        }
-    }
-
-    /*
-     * Class to test for Boolean getSwitch(String)
-     */
-    public final void testGetSwitchString() {
-        assertEquals(Boolean.TRUE, commandLine.getSwitch("--bool"));
-        assertNull(commandLine.getSwitch("--missing"));
-    }
-
-    /*
-     * Class to test for Boolean getSwitch(String, Boolean)
-     */
-    public final void testGetSwitchStringBoolean() {
-        assertEquals(Boolean.TRUE, commandLine.getSwitch("--bool", Boolean.FALSE));
-        assertEquals(Boolean.FALSE, commandLine.getSwitch("--missing", Boolean.FALSE));
-    }
-
-    /*
-     * Class to test for Boolean getSwitch(Option)
-     */
-    public final void testGetSwitchOption() {
-        assertEquals(Boolean.TRUE, commandLine.getSwitch(bool));
-        assertNull(commandLine.getSwitch(missing));
-    }
-
-    /*
-     * Class to test for Boolean getSwitch(Option, Boolean)
-     */
-    public final void testGetSwitchOptionBoolean() {
-        assertEquals(Boolean.TRUE, commandLine.getSwitch(bool, Boolean.FALSE));
-        assertEquals(Boolean.FALSE, commandLine.getSwitch(missing, Boolean.FALSE));
-    }
-
-    /*
-     * Class to test for String getProperty(String)
-     */
-    public final void testGetPropertyString() {
-        assertEquals("present property", commandLine.getProperty("present"));
-        assertNull(commandLine.getProperty("missing"));
-    }
-
-    /*
-     * Class to test for String getProperty(String, String)
-     */
-    public final void testGetPropertyStringString() {
-        assertEquals("present property", commandLine.getProperty("present", "default property"));
-        assertEquals("default property", commandLine.getProperty("missing", "default property"));
-    }
-
-    public final void testGetProperties() {
-        assertTrue(commandLine.getProperties().containsAll(list("present")));
-    }
-
-    /*
-     * Class to test for int getOptionCount(String)
-     */
-    public final void testGetOptionCountString() {
-        // one option, one switch
-        assertTrue(1 <= commandLine.getOptionCount("--present"));
-        assertTrue(1 <= commandLine.getOptionCount("--bool"));
-        assertEquals(0, commandLine.getOptionCount("--missing"));
-    }
-
-    /*
-     * Class to test for int getOptionCount(Option)
-     */
-    public final void testGetOptionCountOption() {
-        // one option, one switch
-        assertTrue(1 <= commandLine.getOptionCount(present));
-        assertTrue(1 <= commandLine.getOptionCount(bool));
-        assertEquals(0, commandLine.getOptionCount(missing));
-    }
-
-    public final void testGetOptions() {
-        //TODO Implement getOptions().
-    }
-
-    public final void testGetOptionTriggers() {
-        //TODO Implement getOptionTriggers().
-    }
-
-    // OLD TESTS FOLLOW
-    public final void testProperties() {
-        final Option option = new PropertyOption();
-        final List args = CLITestCase.list();
-        final WriteableCommandLine writeable = OptionTestCase.commandLine(option, args);
-
-        assertTrue(writeable.getProperties().isEmpty());
-
-        writeable.addProperty("myprop", "myval");
-        assertEquals(1, writeable.getProperties().size());
-        assertEquals("myval", writeable.getProperty("myprop"));
-
-        writeable.addProperty("myprop", "myval2");
-        assertEquals(1, writeable.getProperties().size());
-        assertEquals("myval2", writeable.getProperty("myprop"));
-
-        writeable.addProperty("myprop2", "myval3");
-        assertEquals(2, writeable.getProperties().size());
-        assertEquals("myval3", writeable.getProperty("myprop2"));
-    }
-
-    public final void testOptions() {
-        final Option option = new PropertyOption();
-        final List args = CLITestCase.list();
-        final WriteableCommandLine writeable = OptionTestCase.commandLine(option, args);
-
-        final Option start = CommandTest.buildStartCommand();
-
-        assertFalse(writeable.hasOption(start));
-        assertFalse(writeable.hasOption("start"));
-        assertFalse(writeable.hasOption("go"));
-
-        writeable.addOption(start);
-
-        assertTrue(writeable.hasOption(start));
-        assertTrue(writeable.hasOption("start"));
-        assertTrue(writeable.hasOption("go"));
-    }
-
-    public final void testValues() {
-        final Option option = new PropertyOption();
-        final List args = CLITestCase.list();
-        final WriteableCommandLine writeable = OptionTestCase.commandLine(option, args);
-
-        final Option start = CommandTest.buildStartCommand();
-
-        assertNull(writeable.getValue(start));
-        assertTrue(writeable.getValues(start).isEmpty());
-
-        writeable.addOption(start);
-
-        assertTrue(writeable.getValues(start).isEmpty());
-
-        writeable.addValue(start, "file1");
-
-        assertEquals("file1", writeable.getValue(start));
-        assertEquals("file1", writeable.getValue("start"));
-        assertEquals("file1", writeable.getValue("go"));
-        assertEquals(1, writeable.getValues(start).size());
-        assertEquals(1, writeable.getValues("start").size());
-        assertEquals(1, writeable.getValues("go").size());
-        assertTrue(writeable.getValues(start).contains("file1"));
-        assertTrue(writeable.getValues("start").contains("file1"));
-        assertTrue(writeable.getValues("go").contains("file1"));
-
-        writeable.addValue(start, "file2");
-
-        try {
-            writeable.getValue(start);
-            fail("Cannot get single value if multiple are present");
-        } catch (IllegalStateException ise) {
-            assertEquals(resources.getMessage(ResourceConstants.ARGUMENT_TOO_MANY_VALUES),
-                         ise.getMessage());
-        }
-
-        try {
-            writeable.getValue("start");
-            fail("Cannot get single value if multiple are present");
-        } catch (IllegalStateException ise) {
-            assertEquals(resources.getMessage(ResourceConstants.ARGUMENT_TOO_MANY_VALUES),
-                         ise.getMessage());
-        }
-
-        writeable.getValues(start).add("file3");
-    }
-
-    public final void testSwitches() {
-        final Option option = new PropertyOption();
-        final List args = CLITestCase.list();
-        final WriteableCommandLine writeable = OptionTestCase.commandLine(option, args);
-
-        final Option start = CommandTest.buildStartCommand();
-
-        assertNull(writeable.getSwitch(start));
-        assertNull(writeable.getSwitch("start"));
-        assertNull(writeable.getSwitch("go"));
-
-        writeable.addSwitch(start, true);
-
-        try {
-            writeable.addSwitch(start, false);
-            fail("Switch cannot be changed");
-        } catch (IllegalStateException ise) {
-            assertEquals(resources.getMessage(ResourceConstants.SWITCH_ALREADY_SET),
-                         ise.getMessage());
-        }
-    }
-
-    public final void testSwitches_True() {
-        final Option option = new PropertyOption();
-        final List args = CLITestCase.list();
-        final WriteableCommandLine writeable = OptionTestCase.commandLine(option, args);
-
-        final Option start = CommandTest.buildStartCommand();
-
-        writeable.addSwitch(start, true);
-        assertSame(Boolean.TRUE, writeable.getSwitch(start));
-    }
-
-    public final void testSwitches_False() {
-        final Option option = new PropertyOption();
-        final List args = CLITestCase.list();
-        final WriteableCommandLine writeable = OptionTestCase.commandLine(option, args);
-
-        final Option start = CommandTest.buildStartCommand();
-
-        writeable.addSwitch(start, false);
-        assertSame(Boolean.FALSE, writeable.getSwitch(start));
-    }
-
-    //    public final void testLooksLikeOption() {
-    //        final Option option = new PropertyOption();
-    //        final List args = OptionTestCase.list();
-    //        final WriteableCommandLine commandLine =
-    //            OptionTestCase.commandLine(option, args);
-    //
-    //        assertTrue(commandLine.looksLikeOption("-D"));
-    //        assertFalse(commandLine.looksLikeOption("--help"));
-    //        assertFalse(commandLine.looksLikeOption("+display"));
-    //        assertFalse(commandLine.looksLikeOption("myprefix"));
-    //        assertFalse(commandLine.looksLikeOption("myprefix2"));
-    //        assertFalse(commandLine.looksLikeOption("myprefference"));
-    //        assertFalse(commandLine.looksLikeOption("/SCANDISK"));
-    //        assertFalse(commandLine.looksLikeOption("update"));
-    //    }
-    public final void testGetOptions_Order()
-        throws OptionException {
-        final Option help = DefaultOptionTest.buildHelpOption();
-        final Option login = CommandTest.buildLoginCommand();
-        final Option targets = ArgumentTest.buildTargetsArgument();
-
-        final Group group =
-            new GroupBuilder().withOption(help).withOption(login).withOption(targets).create();
-
-        final Parser parser = new Parser();
-        parser.setGroup(group);
-
-        final CommandLine cl =
-            parser.parse(new String[] { "login", "rob", "--help", "target1", "target2" });
-
-        final Iterator i = cl.getOptions().iterator();
-
-        assertSame(login, i.next());
-        assertSame(help, i.next());
-        assertSame(targets, i.next());
-        assertSame(targets, i.next());
-        assertFalse(i.hasNext());
-    }
-
-    public final void testGetOptionCount()
-        throws OptionException {
-        final Option help = DefaultOptionTest.buildHelpOption();
-        final Option login = CommandTest.buildLoginCommand();
-        final Option targets = ArgumentTest.buildTargetsArgument();
-        final Option display = SwitchTest.buildDisplaySwitch();
-
-        final Group group =
-            new GroupBuilder().withOption(help).withOption(login).withOption(targets)
-                              .withOption(display).create();
-
-        final Parser parser = new Parser();
-        parser.setGroup(group);
-
-        final CommandLine cl =
-            parser.parse(new String[] {
-                             "--help", "login", "rob", "+display", "--help", "--help", "target1",
-                             "target2"
-                         });
-
-        assertEquals(1, cl.getOptionCount(login));
-        assertEquals(3, cl.getOptionCount(help));
-        assertEquals(2, cl.getOptionCount(targets));
-        assertEquals(1, cl.getOptionCount(display));
-    }
-
-    public final void testGetOptionCount_Strings()
-        throws OptionException {
-        final Option help = DefaultOptionTest.buildHelpOption();
-        final Option login = CommandTest.buildLoginCommand();
-        final Option targets = ArgumentTest.buildTargetsArgument();
-        final Option display = SwitchTest.buildDisplaySwitch();
-
-        final Group group =
-            new GroupBuilder().withOption(help).withOption(login).withOption(targets)
-                              .withOption(display).create();
-
-        final Parser parser = new Parser();
-        parser.setGroup(group);
-
-        final CommandLine cl =
-            parser.parse(new String[] {
-                             "--help", "login", "rob", "+display", "--help", "--help", "target1",
-                             "target2"
-                         });
-
-        assertEquals(1, cl.getOptionCount("login"));
-        assertEquals(3, cl.getOptionCount("-?"));
-        assertEquals(1, cl.getOptionCount("+display"));
-    }
-
-    public final void testOptionAsArgument()
-        throws OptionException {
-        final Option p = new DefaultOptionBuilder().withShortName("p").create();
-        final Argument argument = new ArgumentBuilder().create();
-        final Option withArgument =
-            new DefaultOptionBuilder().withShortName("attr").withArgument(argument).create();
-
-        final Group group = new GroupBuilder().withOption(p).withOption(withArgument).create();
-
-        final Parser parser = new Parser();
-        parser.setGroup(group);
-
-        final CommandLine cl = parser.parse(new String[] { "-p", "-attr", "p" });
-
-        assertEquals(1, cl.getOptionCount("-p"));
-        assertTrue(cl.hasOption("-p"));
-        assertTrue(cl.hasOption("-attr"));
-        assertTrue(cl.getValue("-attr").equals("p"));
-    }
-}
+/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements.  See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License.  You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.commons.cli2;import java.util.Collections;import java.util.Iterator;import java.util.List;import org.apache.commons.cli2.builder.ArgumentBuilder;import org.apache.commons.cli2.builder.
 DefaultOptionBuilder;import org.apache.commons.cli2.builder.GroupBuilder;import org.apache.commons.cli2.commandline.Parser;import org.apache.commons.cli2.option.ArgumentTest;import org.apache.commons.cli2.option.CommandTest;import org.apache.commons.cli2.option.DefaultOptionTest;import org.apache.commons.cli2.option.OptionTestCase;import org.apache.commons.cli2.option.PropertyOption;import org.apache.commons.cli2.option.SwitchTest;import org.apache.commons.cli2.resource.ResourceConstants;import org.apache.commons.cli2.resource.ResourceHelper;public abstract class CommandLineTestCase    extends CLITestCase {    private static final ResourceHelper resources = ResourceHelper.getResourceHelper();    public final Option present =        new DefaultOptionBuilder().withLongName("present").withLongName("alsopresent").create();    public final Option missing = new DefaultOptionBuilder().withLongName("missing").create();    public final Option multiple = new DefaultOptionBuilder().wit
 hLongName("multiple").create();    public final Option bool = new DefaultOptionBuilder().withLongName("bool").create();    public final Option root =        new GroupBuilder().withOption(present).withOption(missing).withOption(multiple)                          .withOption(bool).create();    private CommandLine commandLine;    protected abstract CommandLine createCommandLine();    /*     * @see TestCase#setUp()     */    public void setUp()        throws Exception {        super.setUp();        commandLine = createCommandLine();    }    /*     * Class to test for boolean hasOption(String)     */    public final void testHasOptionString() {        assertTrue(commandLine.hasOption("--present"));        assertTrue(commandLine.hasOption("--alsopresent"));        assertFalse(commandLine.hasOption("--missing"));    }    /*     * Class to test for boolean hasOption(Option)     */    public final void testHasOptionOption() {        assertTrue(commandLine.hasOption(present));        
 assertFalse(commandLine.hasOption(missing));    }    public final void testGetOption() {        assertSame(present, commandLine.getOption("--present"));        assertSame(present, commandLine.getOption("--alsopresent"));        //TODO decide whether the following assertion is valid        //assertSame(missing,commandLine.getOption("--missing"));    }    /*     * Class to test for List getValues(String)     */    public final void testGetValuesString() {        assertListContentsEqual(list("present value"), commandLine.getValues("--present"));        assertListContentsEqual(list("value 1", "value 2", "value 3"),                                commandLine.getValues("--multiple"));        assertTrue(commandLine.getValues("--missing").isEmpty());    }    /*     * Class to test for List getValues(String, List)     */    public final void testGetValuesStringList() {        assertListContentsEqual(list("present value"), commandLine.getValues("--present", null));        assertListCo
 ntentsEqual(list("present value"), commandLine.getValues("--alsopresent", null));        assertSame(commandLine.getValues("--missing", Collections.EMPTY_LIST),                   Collections.EMPTY_LIST);        final List def = Collections.singletonList("default value");        assertSame(def, commandLine.getValues("--missing", def));    }    /*     * Class to test for List getValues(Option)     */    public final void testGetValuesOption() {        assertListContentsEqual(list("present value"), commandLine.getValues(present));        assertTrue(commandLine.getValues(missing).isEmpty());    }    /*     * Class to test for List getValues(Option, List)     */    public final void testGetValuesOptionList() {        assertListContentsEqual(list("present value"), commandLine.getValues(present));        assertSame(commandLine.getValues(missing, Collections.EMPTY_LIST), Collections.EMPTY_LIST);        final List defs = Collections.singletonList("custom default");        assertSame(d
 efs, commandLine.getValues(missing, defs));    }    /*     * Class to test for Object getValue(String)     */    public final void testGetValueString() {        assertEquals("present value", commandLine.getValue("--present"));        assertEquals("present value", commandLine.getValue("--alsopresent"));        assertNull(commandLine.getValue("--missing"));        try {            commandLine.getValue("--multiple");            fail("expected IllegalStateException");        } catch (IllegalStateException e) {            assertEquals(resources.getMessage(ResourceConstants.ARGUMENT_TOO_MANY_VALUES),                         e.getMessage());        }    }    /*     * Class to test for Object getValue(String, Object)     */    public final void testGetValueStringObject() {        assertEquals("present value", commandLine.getValue("--present", "default value"));        assertEquals("present value", commandLine.getValue("--alsopresent", "default value"));        assertEquals("default 
 value", commandLine.getValue("--missing", "default value"));        try {            commandLine.getValue("--multiple");            fail("expected IllegalStateException");        } catch (IllegalStateException e) {            assertEquals(resources.getMessage(ResourceConstants.ARGUMENT_TOO_MANY_VALUES),                         e.getMessage());        }    }    /*     * Class to test for Object getValue(Option)     */    public final void testGetValueOption() {        assertEquals("present value", commandLine.getValue(present));        assertNull(commandLine.getValue(missing));        try {            commandLine.getValue(multiple);            fail("expected IllegalStateException");        } catch (IllegalStateException e) {            assertEquals(resources.getMessage(ResourceConstants.ARGUMENT_TOO_MANY_VALUES),                         e.getMessage());        }    }    /*     * Class to test for Object getValue(Option, Object)     */    public final void testGetValueOptionOb
 ject() {        assertEquals("present value", commandLine.getValue(present, "default value"));        assertEquals("default value", commandLine.getValue(missing, "default value"));        try {            commandLine.getValue(multiple);            fail("expected IllegalStateException");        } catch (IllegalStateException e) {            assertEquals(resources.getMessage(ResourceConstants.ARGUMENT_TOO_MANY_VALUES),                         e.getMessage());        }    }    /*     * Class to test for Boolean getSwitch(String)     */    public final void testGetSwitchString() {        assertEquals(Boolean.TRUE, commandLine.getSwitch("--bool"));        assertNull(commandLine.getSwitch("--missing"));    }    /*     * Class to test for Boolean getSwitch(String, Boolean)     */    public final void testGetSwitchStringBoolean() {        assertEquals(Boolean.TRUE, commandLine.getSwitch("--bool", Boolean.FALSE));        assertEquals(Boolean.FALSE, commandLine.getSwitch("--missing", 
 Boolean.FALSE));    }    /*     * Class to test for Boolean getSwitch(Option)     */    public final void testGetSwitchOption() {        assertEquals(Boolean.TRUE, commandLine.getSwitch(bool));        assertNull(commandLine.getSwitch(missing));    }    /*     * Class to test for Boolean getSwitch(Option, Boolean)     */    public final void testGetSwitchOptionBoolean() {        assertEquals(Boolean.TRUE, commandLine.getSwitch(bool, Boolean.FALSE));        assertEquals(Boolean.FALSE, commandLine.getSwitch(missing, Boolean.FALSE));    }    /*     * Class to test for String getProperty(String)     */    public final void testGetPropertyString() {        assertEquals("present property", commandLine.getProperty("present"));        assertNull(commandLine.getProperty("missing"));    }    /*     * Class to test for String getProperty(String, String)     */    public final void testGetPropertyStringString() {        assertEquals("present property", commandLine.getProperty("present", 
 "default property"));        assertEquals("default property", commandLine.getProperty("missing", "default property"));    }    public final void testGetProperties() {        assertTrue(commandLine.getProperties().containsAll(list("present")));    }    /*     * Class to test for int getOptionCount(String)     */    public final void testGetOptionCountString() {        // one option, one switch        assertTrue(1 <= commandLine.getOptionCount("--present"));        assertTrue(1 <= commandLine.getOptionCount("--bool"));        assertEquals(0, commandLine.getOptionCount("--missing"));    }    /*     * Class to test for int getOptionCount(Option)     */    public final void testGetOptionCountOption() {        // one option, one switch        assertTrue(1 <= commandLine.getOptionCount(present));        assertTrue(1 <= commandLine.getOptionCount(bool));        assertEquals(0, commandLine.getOptionCount(missing));    }    public final void testGetOptions() {        //TODO Implement 
 getOptions().    }    public final void testGetOptionTriggers() {        //TODO Implement getOptionTriggers().    }    // OLD TESTS FOLLOW    public final void testProperties() {        final Option option = new PropertyOption();        final List args = CLITestCase.list();        final WriteableCommandLine writeable = OptionTestCase.commandLine(option, args);        assertTrue(writeable.getProperties().isEmpty());        writeable.addProperty("myprop", "myval");        assertEquals(1, writeable.getProperties().size());        assertEquals("myval", writeable.getProperty("myprop"));        writeable.addProperty("myprop", "myval2");        assertEquals(1, writeable.getProperties().size());        assertEquals("myval2", writeable.getProperty("myprop"));        writeable.addProperty("myprop2", "myval3");        assertEquals(2, writeable.getProperties().size());        assertEquals("myval3", writeable.getProperty("myprop2"));    }    public final void testOptions() {        final
  Option option = new PropertyOption();        final List args = CLITestCase.list();        final WriteableCommandLine writeable = OptionTestCase.commandLine(option, args);        final Option start = CommandTest.buildStartCommand();        assertFalse(writeable.hasOption(start));        assertFalse(writeable.hasOption("start"));        assertFalse(writeable.hasOption("go"));        writeable.addOption(start);        assertTrue(writeable.hasOption(start));        assertTrue(writeable.hasOption("start"));        assertTrue(writeable.hasOption("go"));    }    public final void testValues() {        final Option option = new PropertyOption();        final List args = CLITestCase.list();        final WriteableCommandLine writeable = OptionTestCase.commandLine(option, args);        final Option start = CommandTest.buildStartCommand();        assertNull(writeable.getValue(start));        assertTrue(writeable.getValues(start).isEmpty());        writeable.addOption(start);        ass
 ertTrue(writeable.getValues(start).isEmpty());        writeable.addValue(start, "file1");        assertEquals("file1", writeable.getValue(start));        assertEquals("file1", writeable.getValue("start"));        assertEquals("file1", writeable.getValue("go"));        assertEquals(1, writeable.getValues(start).size());        assertEquals(1, writeable.getValues("start").size());        assertEquals(1, writeable.getValues("go").size());        assertTrue(writeable.getValues(start).contains("file1"));        assertTrue(writeable.getValues("start").contains("file1"));        assertTrue(writeable.getValues("go").contains("file1"));        writeable.addValue(start, "file2");        try {            writeable.getValue(start);            fail("Cannot get single value if multiple are present");        } catch (IllegalStateException ise) {            assertEquals(resources.getMessage(ResourceConstants.ARGUMENT_TOO_MANY_VALUES),                         ise.getMessage());        }     
    try {            writeable.getValue("start");            fail("Cannot get single value if multiple are present");        } catch (IllegalStateException ise) {            assertEquals(resources.getMessage(ResourceConstants.ARGUMENT_TOO_MANY_VALUES),                         ise.getMessage());        }        writeable.getValues(start).add("file3");    }    public final void testSwitches() {        final Option option = new PropertyOption();        final List args = CLITestCase.list();        final WriteableCommandLine writeable = OptionTestCase.commandLine(option, args);        final Option start = CommandTest.buildStartCommand();        assertNull(writeable.getSwitch(start));        assertNull(writeable.getSwitch("start"));        assertNull(writeable.getSwitch("go"));        writeable.addSwitch(start, true);        try {            writeable.addSwitch(start, false);            fail("Switch cannot be changed");        } catch (IllegalStateException ise) {            assert
 Equals(resources.getMessage(ResourceConstants.SWITCH_ALREADY_SET),                         ise.getMessage());        }    }    public final void testSwitches_True() {        final Option option = new PropertyOption();        final List args = CLITestCase.list();        final WriteableCommandLine writeable = OptionTestCase.commandLine(option, args);        final Option start = CommandTest.buildStartCommand();        writeable.addSwitch(start, true);        assertSame(Boolean.TRUE, writeable.getSwitch(start));    }    public final void testSwitches_False() {        final Option option = new PropertyOption();        final List args = CLITestCase.list();        final WriteableCommandLine writeable = OptionTestCase.commandLine(option, args);        final Option start = CommandTest.buildStartCommand();        writeable.addSwitch(start, false);        assertSame(Boolean.FALSE, writeable.getSwitch(start));    }    //    public final void testLooksLikeOption() {    //        final Op
 tion option = new PropertyOption();    //        final List args = OptionTestCase.list();    //        final WriteableCommandLine commandLine =    //            OptionTestCase.commandLine(option, args);    //    //        assertTrue(commandLine.looksLikeOption("-D"));    //        assertFalse(commandLine.looksLikeOption("--help"));    //        assertFalse(commandLine.looksLikeOption("+display"));    //        assertFalse(commandLine.looksLikeOption("myprefix"));    //        assertFalse(commandLine.looksLikeOption("myprefix2"));    //        assertFalse(commandLine.looksLikeOption("myprefference"));    //        assertFalse(commandLine.looksLikeOption("/SCANDISK"));    //        assertFalse(commandLine.looksLikeOption("update"));    //    }    public final void testGetOptions_Order()        throws OptionException {        final Option help = DefaultOptionTest.buildHelpOption();        final Option login = CommandTest.buildLoginCommand();        final Option targets = Argume
 ntTest.buildTargetsArgument();        final Group group =            new GroupBuilder().withOption(help).withOption(login).withOption(targets).create();        final Parser parser = new Parser();        parser.setGroup(group);        final CommandLine cl =            parser.parse(new String[] { "login", "rob", "--help", "target1", "target2" });        final Iterator i = cl.getOptions().iterator();        assertSame(login, i.next());        assertSame(help, i.next());        assertSame(targets, i.next());        assertSame(targets, i.next());        assertFalse(i.hasNext());    }    public final void testGetOptionCount()        throws OptionException {        final Option help = DefaultOptionTest.buildHelpOption();        final Option login = CommandTest.buildLoginCommand();        final Option targets = ArgumentTest.buildTargetsArgument();        final Option display = SwitchTest.buildDisplaySwitch();        final Group group =            new GroupBuilder().withOption(help).
 withOption(login).withOption(targets)                              .withOption(display).create();        final Parser parser = new Parser();        parser.setGroup(group);        final CommandLine cl =            parser.parse(new String[] {                             "--help", "login", "rob", "+display", "--help", "--help", "target1",                             "target2"                         });        assertEquals(1, cl.getOptionCount(login));        assertEquals(3, cl.getOptionCount(help));        assertEquals(2, cl.getOptionCount(targets));        assertEquals(1, cl.getOptionCount(display));    }    public final void testGetOptionCount_Strings()        throws OptionException {        final Option help = DefaultOptionTest.buildHelpOption();        final Option login = CommandTest.buildLoginCommand();        final Option targets = ArgumentTest.buildTargetsArgument();        final Option display = SwitchTest.buildDisplaySwitch();        final Group group =            ne
 w GroupBuilder().withOption(help).withOption(login).withOption(targets)                              .withOption(display).create();        final Parser parser = new Parser();        parser.setGroup(group);        final CommandLine cl =            parser.parse(new String[] {                             "--help", "login", "rob", "+display", "--help", "--help", "target1",                             "target2"                         });        assertEquals(1, cl.getOptionCount("login"));        assertEquals(3, cl.getOptionCount("-?"));        assertEquals(1, cl.getOptionCount("+display"));    }    public final void testOptionAsArgument()        throws OptionException {        final Option p = new DefaultOptionBuilder().withShortName("p").create();        final Argument argument = new ArgumentBuilder().create();        final Option withArgument =            new DefaultOptionBuilder().withShortName("attr").withArgument(argument).create();        final Group group = new GroupBuild
 er().withOption(p).withOption(withArgument).create();        final Parser parser = new Parser();        parser.setGroup(group);        final CommandLine cl = parser.parse(new String[] { "-p", "-attr", "p" });        assertEquals(1, cl.getOptionCount("-p"));        assertTrue(cl.hasOption("-p"));        assertTrue(cl.hasOption("-attr"));        assertTrue(cl.getValue("-attr").equals("p"));    }}
\ No newline at end of file

Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli2/DocumentationTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/DocumentationTest.java?rev=639941&r1=639940&r2=639941&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli2/DocumentationTest.java (original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli2/DocumentationTest.java Fri Mar 21 19:49:41 2008
@@ -1,445 +1 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.cli2;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.apache.commons.cli2.builder.ArgumentBuilder;
-import org.apache.commons.cli2.builder.DefaultOptionBuilder;
-import org.apache.commons.cli2.builder.GroupBuilder;
-import org.apache.commons.cli2.commandline.Parser;
-import org.apache.commons.cli2.commandline.WriteableCommandLineImpl;
-import org.apache.commons.cli2.option.DefaultOption;
-import org.apache.commons.cli2.option.PropertyOption;
-import org.apache.commons.cli2.util.HelpFormatter;
-
-/**
- * @author Rob
- */
-public class DocumentationTest extends TestCase {
-
-    public void testBasicUsage() throws IOException, OptionException {
-        HelpFormatter helpFormatter = new HelpFormatter();
-        //ignore all printed
-        helpFormatter.setPrintWriter(new PrintWriter(new StringWriter()));
-
-        /*
-         * --version -? -h --help -log file -s|-q|-v|-d Bursting File/Num/Date
-         * validation Switches Commands Auto help Auto exception help
-         *  
-         */
-        DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
-        Option version =
-            obuilder
-                .withLongName("version")
-                .withDescription("Displays version information and then exits")
-                .create();
-
-        Option help =
-            obuilder
-                .withShortName("h")
-                .withShortName("?")
-                .withLongName("help")
-                .withDescription("Displays help on usage and then exits")
-                .create();
-
-        ArgumentBuilder abuilder = new ArgumentBuilder();
-        Argument logFile =
-            abuilder
-                .withDescription("The log file to write to")
-                .withName("file")
-                .withMinimum(1)
-                .withMaximum(1)
-                .create();
-        Option log =
-            obuilder
-                .withArgument(logFile)
-                .withShortName("log")
-                .withDescription("Log progress information to a file")
-                .create();
-
-        GroupBuilder gbuilder = new GroupBuilder();
-        Group outputQuality =
-            gbuilder
-                .withName("quality")
-                .withDescription("Controls the quality of console output")
-                .withMaximum(1)
-                .withOption(
-                    obuilder
-                        .withShortName("s")
-                        .withDescription("Silent")
-                        .create())
-                .withOption(
-                    obuilder
-                        .withShortName("q")
-                        .withDescription("Quiet")
-                        .create())
-                .withOption(
-                    obuilder
-                        .withShortName("n")
-                        .withDescription("Normal")
-                        .create())
-                .withOption(
-                    obuilder
-                        .withShortName("v")
-                        .withDescription("Verbose")
-                        .create())
-                .withOption(
-                    obuilder
-                        .withShortName("d")
-                        .withDescription("Debug")
-                        .create())
-                .create();
-
-        Group options =
-            new GroupBuilder()
-                .withName("options")
-                .withOption(version)
-                .withOption(help)
-                .withOption(log)
-                .withOption(outputQuality)
-                .create();
-
-        final String[] args = new String[] { "--bad-option" };
-
-        Parser parser = new Parser();
-        parser.setHelpFormatter(helpFormatter);
-        parser.setGroup(options);
-        parser.setHelpOption(help);
-        CommandLine commandLine = parser.parseAndHelp(args);
-        if (commandLine != null) {
-            if (commandLine.hasOption(version)) {
-                System.out.println("MyApp ver 1.0");
-                return;
-            }
-            if (commandLine.hasOption("-log")) {
-                String filename = (String)commandLine.getValue("-log");
-                //...
-            }
-        }
-
-        try {
-            commandLine = parser.parse(args);
-            fail("Unexpected Option!");
-        }
-        catch (OptionException uoe) {
-            assertEquals(
-                "Unexpected --bad-option while processing options",
-                uoe.getMessage());
-        }
-    }
-    
-    public void testManualIntroduction() {
-        
-        DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
-        ArgumentBuilder aBuilder = new ArgumentBuilder();
-        GroupBuilder gBuilder = new GroupBuilder();
-        
-        DefaultOption xmlOption = 
-            oBuilder
-                .withLongName("xml")
-                .withDescription("Output using xml format")
-                .create();
-        
-        Argument pathArgument = 
-            aBuilder
-                .withName("path")
-                .withMinimum(1)
-                .withMaximum(1)
-                .create();
-        
-        Group outputChildren = 
-            gBuilder
-                .withOption(xmlOption)
-                .create();
-        
-        Option outputOption = 
-            oBuilder
-                .withLongName("output")
-                .withDescription("Outputs to a file")
-                .withArgument(pathArgument)
-                .withChildren(outputChildren)
-                .create();
-        
-        ///////////////////////////////////////////////////
-        
-        Group options = outputChildren;
-        HelpFormatter hf = new HelpFormatter();
-
-        Parser p = new Parser();
-        p.setGroup(options);
-        p.setHelpFormatter(hf);
-        p.setHelpTrigger("--help");
-        CommandLine cl = p.parseAndHelp(new String[]{});
-        if(cl==null) {
-            System.exit(-1);
-        }
-        
-        //////////////////////////////////////////////////
-        
-        cl = new WriteableCommandLineImpl(outputChildren,new ArrayList());
-        
-        // if we have --output option
-        if(cl.hasOption("--output")) {
-            // grab the path
-            String path = (String)cl.getValue("--output");
-            // grab the format
-            boolean xml = cl.hasOption("--xml");
-            // configure the application's output
-            configureOutput(path,xml);
-        }
-        
-        
-                
-        
-    }
-
-    private void configureOutput(String path, boolean xml) {
-        // TODO Auto-generated method stub
-        
-    }
-
-    public void testExampleAnt() throws IOException, OptionException {
-        // Apache Ant version 1.6.1 compiled on February 12 2004
-
-        final DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
-        final ArgumentBuilder abuilder = new ArgumentBuilder();
-        final GroupBuilder gbuilder = new GroupBuilder();
-
-        Option help =
-            obuilder
-                .withShortName("help")
-                .withShortName("h")
-                .withDescription("print this message")
-                .create();
-        Option projecthelp =
-            obuilder
-                .withShortName("projecthelp")
-                .withShortName("p")
-                .withDescription("print project help information")
-                .create();
-        Option version =
-            obuilder
-                .withShortName("version")
-                .withDescription("print the version information and exit")
-                .create();
-        Option diagnostics =
-            obuilder
-                .withShortName("diagnostics")
-                .withDescription("print information that might be helpful to diagnose or report problems.")
-                .create();
-        Option quiet =
-            obuilder
-                .withShortName("quiet")
-                .withShortName("q")
-                .withDescription("be extra quiet")
-                .create();
-        Option verbose =
-            obuilder
-                .withShortName("verbose")
-                .withShortName("v")
-                .withDescription("be extra verbose")
-                .create();
-        Option debug =
-            obuilder
-                .withShortName("debug")
-                .withShortName("d")
-                .withDescription("print debugging information")
-                .create();
-        Option emacs =
-            obuilder
-                .withShortName("emacs")
-                .withShortName("e")
-                .withDescription("produce logging information without adornments")
-                .create();
-        Option lib =
-            obuilder
-                .withShortName("lib")
-                .withDescription("specifies a path to search for jars and classes")
-                .withArgument(
-                    abuilder
-                        .withName("path")
-                        .withMinimum(1)
-                        .withMaximum(1)
-                        .create())
-                .create();
-        Option logfile =
-            obuilder
-                .withShortName("logfile")
-                .withShortName("l")
-                .withDescription("use given file for log")
-                .withArgument(
-                    abuilder
-                        .withName("file")
-                        .withMinimum(1)
-                        .withMaximum(1)
-                        .create())
-                .create();
-        Option logger =
-            obuilder
-                .withShortName("logger")
-                .withDescription("the class which is to perform logging")
-                .withArgument(
-                    abuilder
-                        .withName("classname")
-                        .withMinimum(1)
-                        .withMaximum(1)
-                        .create())
-                .create();
-        Option listener =
-            obuilder
-                .withShortName("listener")
-                .withDescription("add an instance of class as a project listener")
-                .withArgument(
-                    abuilder
-                        .withName("classname")
-                        .withMinimum(1)
-                        .withMaximum(1)
-                        .create())
-                .create();
-        Option noinput =
-            obuilder
-                .withShortName("noinput")
-                .withDescription("do not allow interactive input")
-                .create();
-        Option buildfile =
-            obuilder
-                .withShortName("buildfile")
-                .withShortName("file")
-                .withShortName("f")
-                .withDescription("use given buildfile")
-                .withArgument(
-                    abuilder
-                        .withName("file")
-                        .withMinimum(1)
-                        .withMaximum(1)
-                        .create())
-                .create();
-        Option property = new PropertyOption();
-        Option propertyfile =
-            obuilder
-                .withShortName("propertyfile")
-                .withDescription("load all properties from file with -D properties taking precedence")
-                .withArgument(
-                    abuilder
-                        .withName("name")
-                        .withMinimum(1)
-                        .withMaximum(1)
-                        .create())
-                .create();
-        Option inputhandler =
-            obuilder
-                .withShortName("inputhandler")
-                .withDescription("the class which will handle input requests")
-                .withArgument(
-                    abuilder
-                        .withName("class")
-                        .withMinimum(1)
-                        .withMaximum(1)
-                        .create())
-                .create();
-        Option find =
-            obuilder
-                .withShortName("find")
-                .withShortName("s")
-                .withDescription("search for buildfile towards the root of the filesystem and use it")
-                .withArgument(
-                    abuilder
-                        .withName("file")
-                        .withMinimum(1)
-                        .withMaximum(1)
-                        .create())
-                .create();
-        Option targets = abuilder.withName("target").create();
-
-        Group options =
-            gbuilder
-                .withName("options")
-                .withOption(help)
-                .withOption(projecthelp)
-                .withOption(version)
-                .withOption(diagnostics)
-                .withOption(quiet)
-                .withOption(verbose)
-                .withOption(debug)
-                .withOption(emacs)
-                .withOption(lib)
-                .withOption(logfile)
-                .withOption(logger)
-                .withOption(listener)
-                .withOption(noinput)
-                .withOption(buildfile)
-                .withOption(property)
-                .withOption(propertyfile)
-                .withOption(inputhandler)
-                .withOption(find)
-                .withOption(targets)
-                .create();
-        
-        /////////////////////////////////////
-        String[] args = new String[]{};
-        
-        Parser parser = new Parser();
-        parser.setGroup(options);
-        CommandLine cl = parser.parse(args);
-        
-        if(cl.hasOption(help)) {
-            //displayHelp();
-            return;
-        }
-        if(cl.hasOption("-version")) {
-            //displayVersion();
-            return;
-        }
-        if(cl.hasOption(logfile)) {
-            String file = (String)cl.getValue(logfile);
-            //setLogFile();
-        }
-        List targetList = cl.getValues(targets);
-        for (Iterator i = targetList.iterator(); i.hasNext();) {
-            String target = (String) i.next();
-            //doTarget(target);
-        }
-        
-        /////////////////////////////////////
-
-        HelpFormatter hf = new HelpFormatter();
-        hf.setShellCommand("ant");
-        hf.getFullUsageSettings().add(DisplaySetting.DISPLAY_GROUP_NAME);
-        hf.getFullUsageSettings().add(DisplaySetting.DISPLAY_GROUP_ARGUMENT);
-        hf.getFullUsageSettings().remove(DisplaySetting.DISPLAY_GROUP_EXPANDED);
-
-        hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_PROPERTY_OPTION);
-        hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_PARENT_ARGUMENT);
-        hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_ARGUMENT_BRACKETED);
-
-        hf.getDisplaySettings().remove(DisplaySetting.DISPLAY_GROUP_ARGUMENT);
-
-        hf.setGroup(options);
-        // redirect printed stuff to a string
-        hf.setPrintWriter(new PrintWriter(new StringWriter()));
-        hf.print();
-
-    }
-}
+/** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements.  See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License.  You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.commons.cli2;import java.io.IOException;import java.io.PrintWriter;import java.io.StringWriter;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import junit.
 framework.TestCase;import org.apache.commons.cli2.builder.ArgumentBuilder;import org.apache.commons.cli2.builder.DefaultOptionBuilder;import org.apache.commons.cli2.builder.GroupBuilder;import org.apache.commons.cli2.commandline.Parser;import org.apache.commons.cli2.commandline.WriteableCommandLineImpl;import org.apache.commons.cli2.option.DefaultOption;import org.apache.commons.cli2.option.PropertyOption;import org.apache.commons.cli2.util.HelpFormatter;/** * @author Rob */public class DocumentationTest extends TestCase {    public void testBasicUsage() throws IOException, OptionException {        HelpFormatter helpFormatter = new HelpFormatter();        //ignore all printed        helpFormatter.setPrintWriter(new PrintWriter(new StringWriter()));        /*         * --version -? -h --help -log file -s|-q|-v|-d Bursting File/Num/Date         * validation Switches Commands Auto help Auto exception help         *         */        DefaultOptionBuilder obuilder = new DefaultOp
 tionBuilder();        Option version =            obuilder                .withLongName("version")                .withDescription("Displays version information and then exits")                .create();        Option help =            obuilder                .withShortName("h")                .withShortName("?")                .withLongName("help")                .withDescription("Displays help on usage and then exits")                .create();        ArgumentBuilder abuilder = new ArgumentBuilder();        Argument logFile =            abuilder                .withDescription("The log file to write to")                .withName("file")                .withMinimum(1)                .withMaximum(1)                .create();        Option log =            obuilder                .withArgument(logFile)                .withShortName("log")                .withDescription("Log progress information to a file")                .create();        GroupBuilder gbuilder = new GroupBui
 lder();        Group outputQuality =            gbuilder                .withName("quality")                .withDescription("Controls the quality of console output")                .withMaximum(1)                .withOption(                    obuilder                        .withShortName("s")                        .withDescription("Silent")                        .create())                .withOption(                    obuilder                        .withShortName("q")                        .withDescription("Quiet")                        .create())                .withOption(                    obuilder                        .withShortName("n")                        .withDescription("Normal")                        .create())                .withOption(                    obuilder                        .withShortName("v")                        .withDescription("Verbose")                        .create())                .withOption(                    obuilder    
                     .withShortName("d")                        .withDescription("Debug")                        .create())                .create();        Group options =            new GroupBuilder()                .withName("options")                .withOption(version)                .withOption(help)                .withOption(log)                .withOption(outputQuality)                .create();        final String[] args = new String[] { "--bad-option" };        Parser parser = new Parser();        parser.setHelpFormatter(helpFormatter);        parser.setGroup(options);        parser.setHelpOption(help);        CommandLine commandLine = parser.parseAndHelp(args);        if (commandLine != null) {            if (commandLine.hasOption(version)) {                System.out.println("MyApp ver 1.0");                return;            }            if (commandLine.hasOption("-log")) {                String filename = (String)commandLine.getValue("-log");                //.
 ..            }        }        try {            commandLine = parser.parse(args);            fail("Unexpected Option!");        }        catch (OptionException uoe) {            assertEquals(                "Unexpected --bad-option while processing options",                uoe.getMessage());        }    }    public void testManualIntroduction() {        DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();        ArgumentBuilder aBuilder = new ArgumentBuilder();        GroupBuilder gBuilder = new GroupBuilder();        DefaultOption xmlOption =            oBuilder                .withLongName("xml")                .withDescription("Output using xml format")                .create();        Argument pathArgument =            aBuilder                .withName("path")                .withMinimum(1)                .withMaximum(1)                .create();        Group outputChildren =            gBuilder                .withOption(xmlOption)                .create();     
    Option outputOption =            oBuilder                .withLongName("output")                .withDescription("Outputs to a file")                .withArgument(pathArgument)                .withChildren(outputChildren)                .create();        ///////////////////////////////////////////////////        Group options = outputChildren;        HelpFormatter hf = new HelpFormatter();        Parser p = new Parser();        p.setGroup(options);        p.setHelpFormatter(hf);        p.setHelpTrigger("--help");        CommandLine cl = p.parseAndHelp(new String[]{});        if(cl==null) {            System.exit(-1);        }        //////////////////////////////////////////////////        cl = new WriteableCommandLineImpl(outputChildren,new ArrayList());        // if we have --output option        if(cl.hasOption("--output")) {            // grab the path            String path = (String)cl.getValue("--output");            // grab the format            boolean xml = cl.h
 asOption("--xml");            // configure the application's output            configureOutput(path,xml);        }    }    private void configureOutput(String path, boolean xml) {        // TODO Auto-generated method stub    }    public void testExampleAnt() throws IOException, OptionException {        // Apache Ant version 1.6.1 compiled on February 12 2004        final DefaultOptionBuilder obuilder = new DefaultOptionBuilder();        final ArgumentBuilder abuilder = new ArgumentBuilder();        final GroupBuilder gbuilder = new GroupBuilder();        Option help =            obuilder                .withShortName("help")                .withShortName("h")                .withDescription("print this message")                .create();        Option projecthelp =            obuilder                .withShortName("projecthelp")                .withShortName("p")                .withDescription("print project help information")                .create();        Option version
  =            obuilder                .withShortName("version")                .withDescription("print the version information and exit")                .create();        Option diagnostics =            obuilder                .withShortName("diagnostics")                .withDescription("print information that might be helpful to diagnose or report problems.")                .create();        Option quiet =            obuilder                .withShortName("quiet")                .withShortName("q")                .withDescription("be extra quiet")                .create();        Option verbose =            obuilder                .withShortName("verbose")                .withShortName("v")                .withDescription("be extra verbose")                .create();        Option debug =            obuilder                .withShortName("debug")                .withShortName("d")                .withDescription("print debugging information")                .create();     
    Option emacs =            obuilder                .withShortName("emacs")                .withShortName("e")                .withDescription("produce logging information without adornments")                .create();        Option lib =            obuilder                .withShortName("lib")                .withDescription("specifies a path to search for jars and classes")                .withArgument(                    abuilder                        .withName("path")                        .withMinimum(1)                        .withMaximum(1)                        .create())                .create();        Option logfile =            obuilder                .withShortName("logfile")                .withShortName("l")                .withDescription("use given file for log")                .withArgument(                    abuilder                        .withName("file")                        .withMinimum(1)                        .withMaximum(1)                  
       .create())                .create();        Option logger =            obuilder                .withShortName("logger")                .withDescription("the class which is to perform logging")                .withArgument(                    abuilder                        .withName("classname")                        .withMinimum(1)                        .withMaximum(1)                        .create())                .create();        Option listener =            obuilder                .withShortName("listener")                .withDescription("add an instance of class as a project listener")                .withArgument(                    abuilder                        .withName("classname")                        .withMinimum(1)                        .withMaximum(1)                        .create())                .create();        Option noinput =            obuilder                .withShortName("noinput")                .withDescription("do not allow intera
 ctive input")                .create();        Option buildfile =            obuilder                .withShortName("buildfile")                .withShortName("file")                .withShortName("f")                .withDescription("use given buildfile")                .withArgument(                    abuilder                        .withName("file")                        .withMinimum(1)                        .withMaximum(1)                        .create())                .create();        Option property = new PropertyOption();        Option propertyfile =            obuilder                .withShortName("propertyfile")                .withDescription("load all properties from file with -D properties taking precedence")                .withArgument(                    abuilder                        .withName("name")                        .withMinimum(1)                        .withMaximum(1)                        .create())                .create();        Option 
 inputhandler =            obuilder                .withShortName("inputhandler")                .withDescription("the class which will handle input requests")                .withArgument(                    abuilder                        .withName("class")                        .withMinimum(1)                        .withMaximum(1)                        .create())                .create();        Option find =            obuilder                .withShortName("find")                .withShortName("s")                .withDescription("search for buildfile towards the root of the filesystem and use it")                .withArgument(                    abuilder                        .withName("file")                        .withMinimum(1)                        .withMaximum(1)                        .create())                .create();        Option targets = abuilder.withName("target").create();        Group options =            gbuilder                .withName("options"
 )                .withOption(help)                .withOption(projecthelp)                .withOption(version)                .withOption(diagnostics)                .withOption(quiet)                .withOption(verbose)                .withOption(debug)                .withOption(emacs)                .withOption(lib)                .withOption(logfile)                .withOption(logger)                .withOption(listener)                .withOption(noinput)                .withOption(buildfile)                .withOption(property)                .withOption(propertyfile)                .withOption(inputhandler)                .withOption(find)                .withOption(targets)                .create();        /////////////////////////////////////        String[] args = new String[]{};        Parser parser = new Parser();        parser.setGroup(options);        CommandLine cl = parser.parse(args);        if(cl.hasOption(help)) {            //displayHelp();            ret
 urn;        }        if(cl.hasOption("-version")) {            //displayVersion();            return;        }        if(cl.hasOption(logfile)) {            String file = (String)cl.getValue(logfile);            //setLogFile();        }        List targetList = cl.getValues(targets);        for (Iterator i = targetList.iterator(); i.hasNext();) {            String target = (String) i.next();            //doTarget(target);        }        /////////////////////////////////////        HelpFormatter hf = new HelpFormatter();        hf.setShellCommand("ant");        hf.getFullUsageSettings().add(DisplaySetting.DISPLAY_GROUP_NAME);        hf.getFullUsageSettings().add(DisplaySetting.DISPLAY_GROUP_ARGUMENT);        hf.getFullUsageSettings().remove(DisplaySetting.DISPLAY_GROUP_EXPANDED);        hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_PROPERTY_OPTION);        hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_PARENT_ARGUMENT);        hf.getLineUsageSettings().add(Displ
 aySetting.DISPLAY_ARGUMENT_BRACKETED);        hf.getDisplaySettings().remove(DisplaySetting.DISPLAY_GROUP_ARGUMENT);        hf.setGroup(options);        // redirect printed stuff to a string        hf.setPrintWriter(new PrintWriter(new StringWriter()));        hf.print();    }}
\ No newline at end of file



Mime
View raw message