You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by jk...@apache.org on 2003/10/20 23:28:18 UTC
cvs commit: jakarta-commons-sandbox/cli/src/test/org/apache/commons/cli2 ApplicationTest.java
jkeyes 2003/10/20 14:28:18
Modified: cli/src/test/org/apache/commons/cli2 ApplicationTest.java
Added: cli/src/test/org/apache/commons/cli2/apps LsTest.java
Log:
- factored out ls test from ApplicationTest
- WIP LsTest
Revision Changes Path
1.1 jakarta-commons-sandbox/cli/src/test/org/apache/commons/cli2/apps/LsTest.java
Index: LsTest.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons-sandbox/cli/src/test/org/apache/commons/cli2/apps/LsTest.java,v 1.1 2003/10/20 21:28:18 jkeyes Exp $
* $Revision: 1.1 $
* $Date: 2003/10/20 21:28:18 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache GroupImpl.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.cli2.apps;
import java.util.ArrayList;
import java.util.List;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.commons.cli2.ArgumentBuilder;
import org.apache.commons.cli2.CommandLine;
import org.apache.commons.cli2.CommandLineParser;
import org.apache.commons.cli2.DefaultOptionBuilder;
import org.apache.commons.cli2.Group;
import org.apache.commons.cli2.GroupBuilder;
import org.apache.commons.cli2.Option;
import org.apache.commons.cli2.OptionException;
import org.apache.commons.cli2.validation.StringValidator;
/**
* <p>
* Test the <code>ls</code> command. Duplicated Option types
* are not tested e.g. -a and -d are the same Option type.
* </p>
*
* <p>
* The following is the man output for 'ls'. See http://www.rt.com/man/ls.1.html.
* </p>
*
* <pre>
* LS(1) FSF LS(1)
*
* NAME
* ls - list directory contents
*
* SYNOPSIS
* ls [OPTION]... [FILE]...
*
* DESCRIPTION
* List information about the FILEs (the current directory by
* default). Sort entries alphabetically if none of -cftuSUX
* nor --sort.
*
* -a, --all
* do not hide entries starting with .
*
* -A, --almost-all
* do not list implied . and ..
*
* -b, --escape
* print octal escapes for nongraphic characters
*
* --block-size=SIZE
* use SIZE-byte blocks
*
* -B, --ignore-backups
* do not list implied entries ending with ~
*
* -c sort by change time; with -l: show ctime
*
* -C list entries by columns
*
* --color[=WHEN]
* control whether color is used to distinguish file
* types. WHEN may be `never', `always', or `auto'
*
* -d, --directory
* list directory entries instead of contents
*
* -D, --dired
* generate output designed for Emacs' dired mode
*
* -f do not sort, enable -aU, disable -lst
*
* -F, --classify
* append indicator (one of /=@|*) to entries
*
* --format=WORD
* across -x, commas -m, horizontal -x, long -l, sin-
* gle-column -1, verbose -l, vertical -C
*
* --full-time
* list both full date and full time
*
* -g (ignored)
*
* -G, --no-group
* inhibit display of group information
*
* -h, --human-readable
* print sizes in human readable format (e.g., 1K 234M
* 2G)
*
* -H, --si
* likewise, but use powers of 1000 not 1024
*
* --indicator-style=WORD
* append indicator with style WORD to entry names:
* none (default), classify (-F), file-type (-p)
*
* -i, --inode
* print index number of each file
*
* -I, --ignore=PATTERN
* do not list implied entries matching shell PATTERN
*
* -k, --kilobytes
* like --block-size=1024
*
* -l use a long listing format
*
* -L, --dereference
* list entries pointed to by symbolic links
*
* -m fill width with a comma separated list of entries
*
* -n, --numeric-uid-gid
* list numeric UIDs and GIDs instead of names
*
* -N, --literal
* print raw entry names (don't treat e.g. control
* characters specially)
*
* -o use long listing format without group info
*
* -p, --file-type
* append indicator (one of /=@|) to entries
*
* -q, --hide-control-chars
* print ? instead of non graphic characters
*
* --show-control-chars
* show non graphic characters as-is (default)
*
* -Q, --quote-name
* enclose entry names in double quotes
*
* --quoting-style=WORD
* use quoting style WORD for entry names: literal,
* shell, shell-always, c, escape
*
* -r, --reverse
* reverse order while sorting
*
* -R, --recursive
* list subdirectories recursively
*
* -s, --size
* print size of each file, in blocks
*
* -S sort by file size
*
* --sort=WORD
* extension -X, none -U, size -S, time -t, version -v
* status -c, time -t, atime -u, access -u, use -u
*
* --time=WORD
* show time as WORD instead of modification time:
* atime, access, use, ctime or status; use specified
* time as sort key if --sort=time
*
* -t sort by modification time
*
* -T, --tabsize=COLS
* assume tab stops at each COLS instead of 8
*
* -u sort by last access time; with -l: show atime
*
* -U do not sort; list entries in directory order
*
* -v sort by version
*
* -w, --width=COLS
* assume screen width instead of current value
*
* -x list entries by lines instead of by columns
*
* -X sort alphabetically by entry extension
*
* -1 list one file per line
*
* --help display this help and exit
*
* --version
* output version information and exit
*
* By default, color is not used to distinguish types of
* files. That is equivalent to using --color=none. Using
* the --color option without the optional WHEN argument is
* equivalent to using --color=always. With --color=auto,
* color codes are output only if standard output is con-
* nected to a terminal (tty).
* </pre>
*
* @author Rob Oxspring
* @author John Keyes
*/
public class LsTest extends TestCase {
/** Option Builder */
private static final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
/** Argument Builder */
private static final ArgumentBuilder aBuilder = new ArgumentBuilder();
/** Group Builder */
private static final GroupBuilder gBuilder = new GroupBuilder();
private static Group options;
public static Test suite() {
return new TestSuite(LsTest.class);
}
/**
* Required ctor.
*
* @param name
* the name of the TestCase
*/
public LsTest(final String name) {
super(name);
}
public void setUp() throws OptionException {
if (LsTest.options == null) {
final Option a = oBuilder
.withShortName("a")
.withLongName("all")
.withDescription("do not hide entries starting with .")
.create();
final Option blockSize = oBuilder
.withLongName("block-size")
.withRequired(false)
.withDescription("use SIZE-byte blocks")
.withArgument(
aBuilder
.withMaximum(1)
.withMinimum(1)
.withInitialSeparator('=')
.create())
.create();
final Option c = oBuilder
.withShortName("c")
.withRequired(false)
.withDescription("with -lt: sort by, and show, ctime (time of last modification of file status information) with -l:show ctime and sort by name otherwise: sort by ctime")
.create();
final List colors = new ArrayList();
colors.add("never");
colors.add("always");
colors.add("auto");
final Option color = oBuilder
.withLongName("color")
.withRequired(false)
.withDescription("control whether color is used to distinguish file types. WHEN may be `never', `always', or `auto'")
.withArgument(
aBuilder
.withMaximum(1)
.withMinimum(1)
.withInitialSeparator('=')
.withValidator(new StringValidator(colors))
.create())
.create();
LsTest.options = gBuilder
.withOption(a)
.withOption(blockSize)
.withOption(c)
.withOption(color)
.create();
}
}
/**
*
*/
public void testLs() throws OptionException {
// create the command line parser
CommandLineParser parser = new CommandLineParser();
parser.setGroup(options);
CommandLine line = parser.parse(new String[] { "--block-size=10", "--color=never" });
assertTrue(line.hasOption("--block-size"));
assertEquals(line.getValue("--block-size"), "10");
assertFalse(line.hasOption("--ignore-backups"));
}
}
1.2 +541 -615 jakarta-commons-sandbox/cli/src/test/org/apache/commons/cli2/ApplicationTest.java
Index: ApplicationTest.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/test/org/apache/commons/cli2/ApplicationTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ApplicationTest.java 18 Oct 2003 22:00:26 -0000 1.1
+++ ApplicationTest.java 20 Oct 2003 21:28:18 -0000 1.2
@@ -1,616 +1,542 @@
-/*
- * $Header$
- * $Revision$
- * $Date$
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 2003 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements normally appear.
- *
- * 4. The names "The Jakarta Project", "Commons", and "Apache Software
- * Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache"
- * nor may "Apache" appear in their names without prior written
- * permission of the Apache GroupImpl.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-package org.apache.commons.cli2;
-
-import java.util.List;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- * <p>
- * This is a collection of tests that test real world
- * applications command lines.
- * </p>
- *
- * <p>
- * The following are the applications that are tested:
- * <ul>
- * <li>Ant</li>
- * </ul>
- * </p>
- *
- * @author John Keyes (john at integralsource.com)
- */
-public class ApplicationTest extends TestCase {
-
- public static Test suite() {
- return new TestSuite(ApplicationTest.class);
- }
-
- public ApplicationTest(String name) {
- super(name);
- }
-
- /**
- *
- */
- public void testLs() throws OptionException {
- DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
- ArgumentBuilder aBuilder = new ArgumentBuilder();
- GroupBuilder gBuilder = new GroupBuilder();
-
- Group options =
- gBuilder
- .withName("ls")
- .withDescription("options")
- .withOption(
- oBuilder
- .withShortName("a")
- .withLongName("all")
- .withDescription("do not hide entries starting with .")
- .create())
- .withOption(
- oBuilder
- .withShortName("A")
- .withLongName("almost-all")
- .withDescription("do not list implied . and ..")
- .create())
- .withOption(
- oBuilder
- .withShortName("b")
- .withLongName("escape")
- .withRequired(false)
- .withDescription("print octal escapes for nongraphic characters")
- .create())
- .withOption(
- oBuilder
- .withLongName("block-size")
- .withRequired(false)
- .withDescription("use SIZE-byte blocks")
- .withArgument(
- aBuilder
- .withMaximum(1)
- .withMinimum(1)
- .withInitialSeparator('=')
- .create())
- .create())
- .withOption(
- oBuilder
- .withShortName("B")
- .withLongName("ignore-backups")
- .withRequired(false)
- .withDescription("do not list implied entried ending with ~")
- .create())
- .withOption(
- oBuilder
- .withShortName("c")
- .withRequired(false)
- .withDescription("with -lt: sort by, and show, ctime (time of last modification of file status information) with -l:show ctime and sort by name otherwise: sort by ctime")
- .create())
- .withOption(
- oBuilder
- .withShortName("C")
- .withRequired(false)
- .withDescription("list entries by columns")
- .create())
- .create();
-
- // create the command line parser
- CommandLineParser parser = new CommandLineParser();
- parser.setGroup(options);
- CommandLine line = parser.parse(new String[] { "--block-size=10" });
-
- assertTrue(line.hasOption("--block-size"));
- assertEquals(line.getValue("--block-size"), "10");
- assertFalse(line.hasOption("--ignore-backups"));
- }
-
- /**
- * Ant test
- */
- public void testAnt() throws OptionException {
-
- final DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
- final ArgumentBuilder abuilder = new ArgumentBuilder();
- final GroupBuilder gbuilder = new GroupBuilder();
-
- final Group options =
- gbuilder
- .withName("ant")
- .withOption(
- obuilder
- .withShortName("help")
- .withDescription("print this message")
- .create())
- .withOption(
- obuilder
- .withShortName("projecthelp")
- .withDescription("print project help information")
- .create())
- .withOption(
- obuilder
- .withShortName("version")
- .withDescription("print the version information and exit")
- .create())
- .withOption(
- obuilder
- .withShortName("diagnostics")
- .withDescription("print information that might be helpful to diagnose or report problems.")
- .create())
- .withOption(
- obuilder
- .withShortName("quiet")
- .withShortName("q")
- .withDescription("be extra quiet")
- .create())
- .withOption(
- obuilder
- .withShortName("verbose")
- .withShortName("v")
- .withDescription("be extra verbose")
- .create())
- .withOption(
- obuilder
- .withShortName("debug")
- .withDescription("print debugging information")
- .create())
- .withOption(
- obuilder
- .withShortName("emacs")
- .withDescription("produce logging information without adornments")
- .create())
- .withOption(
- obuilder
- .withShortName("logfile")
- .withShortName("l")
- .withDescription("use given file for log")
- .withArgument(
- abuilder
- .withName("file")
- .withMinimum(1)
- .withMaximum(1)
- .create())
- .create())
- .withOption(
- obuilder
- .withShortName("logger")
- .withDescription("the class which is to perform logging")
- .withArgument(
- abuilder
- .withName("classname")
- .withMinimum(1)
- .withMaximum(1)
- .create())
- .create())
- .withOption(
- obuilder
- .withShortName("listener")
- .withDescription("add an instance of class as a project listener")
- .withArgument(
- abuilder
- .withName("classname")
- .withMinimum(1)
- .withMaximum(1)
- .create())
- .create())
- .withOption(
- obuilder
- .withShortName("buildfile")
- .withShortName("file")
- .withShortName("f")
- .withDescription("use given buildfile")
- .withArgument(
- abuilder
- .withName("file")
- .withMinimum(1)
- .withMaximum(1)
- .create())
- .create())
- .withOption(PropertyOption.INSTANCE)
- .withOption(
- obuilder
- .withShortName("propertyfile")
- .withDescription("load all properties from file with -D properties taking precedence")
- .withArgument(
- abuilder
- .withName("name")
- .withMinimum(1)
- .withMaximum(1)
- .create())
- .create())
- .withOption(
- obuilder
- .withShortName("inputhandler")
- .withDescription("the class which will handle input requests")
- .withArgument(
- abuilder
- .withName("class")
- .withMinimum(1)
- .withMaximum(1)
- .create())
- .create())
- .withOption(
- obuilder
- .withShortName("find")
- .withDescription("search for buildfile towards the root of the filesystem and use it")
- .withArgument(
- abuilder
- .withName("file")
- .withMinimum(1)
- .withMaximum(1)
- .create())
- .create())
- .withOption(abuilder.withName("target").create())
- .create();
-
- CommandLineParser parser = new CommandLineParser();
- parser.setGroup(options);
- CommandLine line =
- parser.parse(
- new String[] {
- "-buildfile",
- "mybuild.xml",
- "-Dproperty=value",
- "-Dproperty1=value1",
- "-projecthelp",
- "compile",
- "docs" });
-
- // check properties
- assertEquals(2, line.getProperties().size());
- assertEquals("value", line.getProperty("property"));
- assertEquals("value1", line.getProperty("property1"));
-
- // check single values
- assertEquals("mybuild.xml", line.getValue("-buildfile"));
- assertTrue(line.hasOption("-projecthelp"));
- assertFalse(line.hasOption("-help"));
-
- // check targets
- final List unprocessed = line.getUnprocessed();
- assertTrue(unprocessed.isEmpty());
- }
-
- public void testCVS() throws OptionException {
- final DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
- final ArgumentBuilder abuilder = new ArgumentBuilder();
- final CommandBuilder cbuilder = new CommandBuilder();
- final GroupBuilder gbuilder = new GroupBuilder();
-
- final Group commands =
- gbuilder
- .withName("commands")
- .withOption(
- cbuilder
- .withName("add")
- .withName("ad")
- .withName("new")
- .withDescription("Add a new file/directory to the repository")
- .create())
- .withOption(
- cbuilder
- .withName("admin")
- .withName("adm")
- .withName("rcs")
- .withDescription("Administration front end for rcs")
- .create())
- .withOption(
- cbuilder
- .withName("annotate")
- .withName("ann")
- .withDescription("Show last revision where each line was modified")
- .create())
- .withOption(
- cbuilder
- .withName("checkout")
- .withName("co")
- .withName("get")
- .withDescription("Checkout sources for editing")
- .create())
- .withOption(
- cbuilder
- .withName("commit")
- .withName("ci")
- .withName("com")
- .withDescription("Check files into the repository")
- .create())
- .withOption(
- cbuilder
- .withName("diff")
- .withName("di")
- .withName("dif")
- .withDescription("Show differences between revisions")
- .create())
- .withOption(
- cbuilder
- .withName("edit")
- .withDescription("Get ready to edit a watched file")
- .create())
- .withOption(
- cbuilder
- .withName("editors")
- .withDescription("See who is editing a watched file")
- .create())
- .withOption(
- cbuilder
- .withName("export")
- .withName("exp")
- .withName("ex")
- .withDescription("Export sources from CVS, similar to checkout")
- .create())
- .withOption(
- cbuilder
- .withName("history")
- .withName("hi")
- .withName("his")
- .withDescription("Show repository access history")
- .create())
- .withOption(
- cbuilder
- .withName("import")
- .withName("im")
- .withName("imp")
- .withDescription("Import sources into CVS, using vendor branches")
- .create())
- .withOption(
- cbuilder
- .withName("init")
- .withDescription("Create a CVS repository if it doesn't exist")
- .create())
- .withOption(
- cbuilder
- .withName("log")
- .withName("lo")
- .withName("rlog")
- .withDescription("Print out history information for files")
- .create())
- .withOption(
- cbuilder
- .withName("login")
- .withName("logon")
- .withName("lgn")
- .withDescription("Prompt for password for authenticating server")
- .create())
- .withOption(
- cbuilder
- .withName("logout")
- .withDescription("Removes entry in .cvspass for remote repository")
- .create())
- .withOption(
- cbuilder
- .withName("rdiff")
- .withName("patch")
- .withName("pa")
- .withDescription("Create 'patch' format diffs between releases")
- .create())
- .withOption(
- cbuilder
- .withName("release")
- .withName("re")
- .withName("rel")
- .withDescription("Indicate that a Module is no longer in use")
- .create())
- .withOption(
- cbuilder
- .withName("remove")
- .withName("rm")
- .withName("delete")
- .withDescription("Remove an entry from the repository")
- .create())
- .withOption(
- cbuilder
- .withName("rtag")
- .withName("rt")
- .withName("rfreeze")
- .withDescription("Add a symbolic tag to a module")
- .create())
- .withOption(
- cbuilder
- .withName("status")
- .withName("st")
- .withName("stat")
- .withDescription("Display status information on checked out files")
- .create())
- .withOption(
- cbuilder
- .withName("tag")
- .withName("ta")
- .withName("freeze")
- .withDescription("Add a symbolic tag to checked out version of files")
- .create())
- .withOption(
- cbuilder
- .withName("unedit")
- .withDescription("Undo an edit command")
- .create())
- .withOption(
- cbuilder
- .withName("update")
- .withName("up")
- .withName("upd")
- .withDescription("Bring work tree in sync with repository")
- .create())
- .withOption(
- cbuilder
- .withName("watch")
- .withDescription("Set watches")
- .create())
- .withOption(
- cbuilder
- .withName("watchers")
- .withDescription("See who is watching a file")
- .create())
- .withOption(
- cbuilder
- .withName("version")
- .withName("ve")
- .withName("ver")
- .withDescription("????")
- .create())
- .withOption(ArgumentTest.buildTargetsArgument())
- .create();
-
- final Group cvsOptions =
- new GroupBuilder()
- .withName("cvs-options")
- .withOption(
- obuilder
- .withShortName("H")
- .withDescription("Displays usage information for command.")
- .create())
- .withOption(
- obuilder
- .withShortName("Q")
- .withDescription("Cause CVS to be really quiet.")
- .create())
- .withOption(
- obuilder
- .withShortName("q")
- .withDescription("Cause CVS to be somewhat quiet.")
- .create())
- .withOption(
- obuilder
- .withShortName("r")
- .withDescription("Make checked-out files read-only.")
- .create())
- .withOption(
- obuilder
- .withShortName("w")
- .withDescription("Make checked-out files read-write (default).")
- .create())
- .withOption(
- obuilder
- .withShortName("l")
- .withDescription("Turn history logging off.")
- .create())
- .withOption(
- obuilder
- .withShortName("n")
- .withDescription("Do not execute anything that will change the disk.")
- .create())
- .withOption(
- obuilder
- .withShortName("t")
- .withDescription("Show trace of program execution -- try with -n.")
- .create())
- .withOption(
- obuilder
- .withShortName("v")
- .withDescription("CVS version and copyright.")
- .create())
- .withOption(
- obuilder
- .withLongName("crlf")
- .withDescription("Use the Dos line feed for text files (default).")
- .create())
- .withOption(
- obuilder
- .withLongName("lf")
- .withDescription("Use the Unix line feed for text files.")
- .create())
- .withOption(
- obuilder
- .withShortName("T")
- .withDescription("Use 'tmpdir' for temporary files.")
- .withArgument(abuilder.withName("tmpdir").create())
- .create())
- .withOption(
- obuilder
- .withShortName("e")
- .withDescription("Use 'editor' for editing log information.")
- .withArgument(abuilder.withName("editor").create())
- .create())
- .withOption(
- obuilder
- .withShortName("d")
- .withDescription("Overrides $CVSROOT as the root of the CVS tree.")
- .withArgument(abuilder.withName("CVS_root").create())
- .create())
- .withOption(
- obuilder
- .withShortName("f")
- .withDescription("Do not use the ~/.cvsrc file.")
- .create())
- .withOption(
- obuilder
- .withShortName("z")
- .withDescription("Use compression level '#' for net traffic.")
- .withArgument(abuilder.withName("#").create())
- .create())
- .withOption(
- obuilder
- .withShortName("a")
- .withDescription("Authenticate all net traffic.")
- .create())
- .withOption(
- obuilder
- .withShortName("s")
- .withDescription("Set CVS user variable.")
- .withArgument(abuilder.withName("VAR=VAL").create())
- .create())
- .withOption(commands)
- .create();
-
- assertNotNull(cvsOptions);
- }
+/*
+ * $Header$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache GroupImpl.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.commons.cli2;
+
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * <p>
+ * This is a collection of tests that test real world
+ * applications command lines.
+ * </p>
+ *
+ * <p>
+ * The following are the applications that are tested:
+ * <ul>
+ * <li>Ant</li>
+ * </ul>
+ * </p>
+ *
+ * @author John Keyes (john at integralsource.com)
+ */
+public class ApplicationTest extends TestCase {
+
+ public static Test suite() {
+ return new TestSuite(ApplicationTest.class);
+ }
+
+ public ApplicationTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Ant test
+ */
+ public void testAnt() throws OptionException {
+
+ final DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
+ final ArgumentBuilder abuilder = new ArgumentBuilder();
+ final GroupBuilder gbuilder = new GroupBuilder();
+
+ final Group options =
+ gbuilder
+ .withName("ant")
+ .withOption(
+ obuilder
+ .withShortName("help")
+ .withDescription("print this message")
+ .create())
+ .withOption(
+ obuilder
+ .withShortName("projecthelp")
+ .withDescription("print project help information")
+ .create())
+ .withOption(
+ obuilder
+ .withShortName("version")
+ .withDescription("print the version information and exit")
+ .create())
+ .withOption(
+ obuilder
+ .withShortName("diagnostics")
+ .withDescription("print information that might be helpful to diagnose or report problems.")
+ .create())
+ .withOption(
+ obuilder
+ .withShortName("quiet")
+ .withShortName("q")
+ .withDescription("be extra quiet")
+ .create())
+ .withOption(
+ obuilder
+ .withShortName("verbose")
+ .withShortName("v")
+ .withDescription("be extra verbose")
+ .create())
+ .withOption(
+ obuilder
+ .withShortName("debug")
+ .withDescription("print debugging information")
+ .create())
+ .withOption(
+ obuilder
+ .withShortName("emacs")
+ .withDescription("produce logging information without adornments")
+ .create())
+ .withOption(
+ obuilder
+ .withShortName("logfile")
+ .withShortName("l")
+ .withDescription("use given file for log")
+ .withArgument(
+ abuilder
+ .withName("file")
+ .withMinimum(1)
+ .withMaximum(1)
+ .create())
+ .create())
+ .withOption(
+ obuilder
+ .withShortName("logger")
+ .withDescription("the class which is to perform logging")
+ .withArgument(
+ abuilder
+ .withName("classname")
+ .withMinimum(1)
+ .withMaximum(1)
+ .create())
+ .create())
+ .withOption(
+ obuilder
+ .withShortName("listener")
+ .withDescription("add an instance of class as a project listener")
+ .withArgument(
+ abuilder
+ .withName("classname")
+ .withMinimum(1)
+ .withMaximum(1)
+ .create())
+ .create())
+ .withOption(
+ obuilder
+ .withShortName("buildfile")
+ .withShortName("file")
+ .withShortName("f")
+ .withDescription("use given buildfile")
+ .withArgument(
+ abuilder
+ .withName("file")
+ .withMinimum(1)
+ .withMaximum(1)
+ .create())
+ .create())
+ .withOption(PropertyOption.INSTANCE)
+ .withOption(
+ obuilder
+ .withShortName("propertyfile")
+ .withDescription("load all properties from file with -D properties taking precedence")
+ .withArgument(
+ abuilder
+ .withName("name")
+ .withMinimum(1)
+ .withMaximum(1)
+ .create())
+ .create())
+ .withOption(
+ obuilder
+ .withShortName("inputhandler")
+ .withDescription("the class which will handle input requests")
+ .withArgument(
+ abuilder
+ .withName("class")
+ .withMinimum(1)
+ .withMaximum(1)
+ .create())
+ .create())
+ .withOption(
+ obuilder
+ .withShortName("find")
+ .withDescription("search for buildfile towards the root of the filesystem and use it")
+ .withArgument(
+ abuilder
+ .withName("file")
+ .withMinimum(1)
+ .withMaximum(1)
+ .create())
+ .create())
+ .withOption(abuilder.withName("target").create())
+ .create();
+
+ CommandLineParser parser = new CommandLineParser();
+ parser.setGroup(options);
+ CommandLine line =
+ parser.parse(
+ new String[] {
+ "-buildfile",
+ "mybuild.xml",
+ "-Dproperty=value",
+ "-Dproperty1=value1",
+ "-projecthelp",
+ "compile",
+ "docs" });
+
+ // check properties
+ assertEquals(2, line.getProperties().size());
+ assertEquals("value", line.getProperty("property"));
+ assertEquals("value1", line.getProperty("property1"));
+
+ // check single values
+ assertEquals("mybuild.xml", line.getValue("-buildfile"));
+ assertTrue(line.hasOption("-projecthelp"));
+ assertFalse(line.hasOption("-help"));
+
+ // check targets
+ final List unprocessed = line.getUnprocessed();
+ assertTrue(unprocessed.isEmpty());
+ }
+
+ public void testCVS() throws OptionException {
+ final DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
+ final ArgumentBuilder abuilder = new ArgumentBuilder();
+ final CommandBuilder cbuilder = new CommandBuilder();
+ final GroupBuilder gbuilder = new GroupBuilder();
+
+ final Group commands =
+ gbuilder
+ .withName("commands")
+ .withOption(
+ cbuilder
+ .withName("add")
+ .withName("ad")
+ .withName("new")
+ .withDescription("Add a new file/directory to the repository")
+ .create())
+ .withOption(
+ cbuilder
+ .withName("admin")
+ .withName("adm")
+ .withName("rcs")
+ .withDescription("Administration front end for rcs")
+ .create())
+ .withOption(
+ cbuilder
+ .withName("annotate")
+ .withName("ann")
+ .withDescription("Show last revision where each line was modified")
+ .create())
+ .withOption(
+ cbuilder
+ .withName("checkout")
+ .withName("co")
+ .withName("get")
+ .withDescription("Checkout sources for editing")
+ .create())
+ .withOption(
+ cbuilder
+ .withName("commit")
+ .withName("ci")
+ .withName("com")
+ .withDescription("Check files into the repository")
+ .create())
+ .withOption(
+ cbuilder
+ .withName("diff")
+ .withName("di")
+ .withName("dif")
+ .withDescription("Show differences between revisions")
+ .create())
+ .withOption(
+ cbuilder
+ .withName("edit")
+ .withDescription("Get ready to edit a watched file")
+ .create())
+ .withOption(
+ cbuilder
+ .withName("editors")
+ .withDescription("See who is editing a watched file")
+ .create())
+ .withOption(
+ cbuilder
+ .withName("export")
+ .withName("exp")
+ .withName("ex")
+ .withDescription("Export sources from CVS, similar to checkout")
+ .create())
+ .withOption(
+ cbuilder
+ .withName("history")
+ .withName("hi")
+ .withName("his")
+ .withDescription("Show repository access history")
+ .create())
+ .withOption(
+ cbuilder
+ .withName("import")
+ .withName("im")
+ .withName("imp")
+ .withDescription("Import sources into CVS, using vendor branches")
+ .create())
+ .withOption(
+ cbuilder
+ .withName("init")
+ .withDescription("Create a CVS repository if it doesn't exist")
+ .create())
+ .withOption(
+ cbuilder
+ .withName("log")
+ .withName("lo")
+ .withName("rlog")
+ .withDescription("Print out history information for files")
+ .create())
+ .withOption(
+ cbuilder
+ .withName("login")
+ .withName("logon")
+ .withName("lgn")
+ .withDescription("Prompt for password for authenticating server")
+ .create())
+ .withOption(
+ cbuilder
+ .withName("logout")
+ .withDescription("Removes entry in .cvspass for remote repository")
+ .create())
+ .withOption(
+ cbuilder
+ .withName("rdiff")
+ .withName("patch")
+ .withName("pa")
+ .withDescription("Create 'patch' format diffs between releases")
+ .create())
+ .withOption(
+ cbuilder
+ .withName("release")
+ .withName("re")
+ .withName("rel")
+ .withDescription("Indicate that a Module is no longer in use")
+ .create())
+ .withOption(
+ cbuilder
+ .withName("remove")
+ .withName("rm")
+ .withName("delete")
+ .withDescription("Remove an entry from the repository")
+ .create())
+ .withOption(
+ cbuilder
+ .withName("rtag")
+ .withName("rt")
+ .withName("rfreeze")
+ .withDescription("Add a symbolic tag to a module")
+ .create())
+ .withOption(
+ cbuilder
+ .withName("status")
+ .withName("st")
+ .withName("stat")
+ .withDescription("Display status information on checked out files")
+ .create())
+ .withOption(
+ cbuilder
+ .withName("tag")
+ .withName("ta")
+ .withName("freeze")
+ .withDescription("Add a symbolic tag to checked out version of files")
+ .create())
+ .withOption(
+ cbuilder
+ .withName("unedit")
+ .withDescription("Undo an edit command")
+ .create())
+ .withOption(
+ cbuilder
+ .withName("update")
+ .withName("up")
+ .withName("upd")
+ .withDescription("Bring work tree in sync with repository")
+ .create())
+ .withOption(
+ cbuilder
+ .withName("watch")
+ .withDescription("Set watches")
+ .create())
+ .withOption(
+ cbuilder
+ .withName("watchers")
+ .withDescription("See who is watching a file")
+ .create())
+ .withOption(
+ cbuilder
+ .withName("version")
+ .withName("ve")
+ .withName("ver")
+ .withDescription("????")
+ .create())
+ .withOption(ArgumentTest.buildTargetsArgument())
+ .create();
+
+ final Group cvsOptions =
+ new GroupBuilder()
+ .withName("cvs-options")
+ .withOption(
+ obuilder
+ .withShortName("H")
+ .withDescription("Displays usage information for command.")
+ .create())
+ .withOption(
+ obuilder
+ .withShortName("Q")
+ .withDescription("Cause CVS to be really quiet.")
+ .create())
+ .withOption(
+ obuilder
+ .withShortName("q")
+ .withDescription("Cause CVS to be somewhat quiet.")
+ .create())
+ .withOption(
+ obuilder
+ .withShortName("r")
+ .withDescription("Make checked-out files read-only.")
+ .create())
+ .withOption(
+ obuilder
+ .withShortName("w")
+ .withDescription("Make checked-out files read-write (default).")
+ .create())
+ .withOption(
+ obuilder
+ .withShortName("l")
+ .withDescription("Turn history logging off.")
+ .create())
+ .withOption(
+ obuilder
+ .withShortName("n")
+ .withDescription("Do not execute anything that will change the disk.")
+ .create())
+ .withOption(
+ obuilder
+ .withShortName("t")
+ .withDescription("Show trace of program execution -- try with -n.")
+ .create())
+ .withOption(
+ obuilder
+ .withShortName("v")
+ .withDescription("CVS version and copyright.")
+ .create())
+ .withOption(
+ obuilder
+ .withLongName("crlf")
+ .withDescription("Use the Dos line feed for text files (default).")
+ .create())
+ .withOption(
+ obuilder
+ .withLongName("lf")
+ .withDescription("Use the Unix line feed for text files.")
+ .create())
+ .withOption(
+ obuilder
+ .withShortName("T")
+ .withDescription("Use 'tmpdir' for temporary files.")
+ .withArgument(abuilder.withName("tmpdir").create())
+ .create())
+ .withOption(
+ obuilder
+ .withShortName("e")
+ .withDescription("Use 'editor' for editing log information.")
+ .withArgument(abuilder.withName("editor").create())
+ .create())
+ .withOption(
+ obuilder
+ .withShortName("d")
+ .withDescription("Overrides $CVSROOT as the root of the CVS tree.")
+ .withArgument(abuilder.withName("CVS_root").create())
+ .create())
+ .withOption(
+ obuilder
+ .withShortName("f")
+ .withDescription("Do not use the ~/.cvsrc file.")
+ .create())
+ .withOption(
+ obuilder
+ .withShortName("z")
+ .withDescription("Use compression level '#' for net traffic.")
+ .withArgument(abuilder.withName("#").create())
+ .create())
+ .withOption(
+ obuilder
+ .withShortName("a")
+ .withDescription("Authenticate all net traffic.")
+ .create())
+ .withOption(
+ obuilder
+ .withShortName("s")
+ .withDescription("Set CVS user variable.")
+ .withArgument(abuilder.withName("VAR=VAL").create())
+ .create())
+ .withOption(commands)
+ .create();
+
+ assertNotNull(cvsOptions);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org