avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/cli/examples/incompat_options IncompatOptions.java README.txt
Date Tue, 19 Mar 2002 11:09:30 GMT
donaldp     02/03/19 03:09:29

  Added:       cli/examples/incompat_options IncompatOptions.java
  Add in example with incompatible options
  Revision  Changes    Path
  1.1                  jakarta-avalon-excalibur/cli/examples/incompat_options/IncompatOptions.java
  Index: IncompatOptions.java
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
  import java.util.List;
  import org.apache.avalon.excalibur.cli.CLArgsParser;
  import org.apache.avalon.excalibur.cli.CLOption;
  import org.apache.avalon.excalibur.cli.CLOptionDescriptor;
  import org.apache.avalon.excalibur.cli.CLUtil;
   * Demonstrates example of CLI containing incompatible arguments.
   * In this demo the quiet and verbose options are incompatible with
   * each other.
   * @author <a href="peter@apache.org">Peter Donald</a>
  public class IncompatOptions
      // Define our short one-letter option identifiers.
      private static final int VERBOSE_OPT = 'v';
      private static final int QUIET_OPT = 'q';
       *  Define the understood options. Each CLOptionDescriptor contains:
       * - The "long" version of the option. Eg, "quiet" means that "--quiet" will
       * be recognised.
       * - The option flags, governing the option's argument(s).
       * - The "short" version of the option. Eg, 'q' means that "-q" will be
       * recognised.
       * - A description of the option.
      private static final CLOptionDescriptor[] OPTIONS = new CLOptionDescriptor[]
          new CLOptionDescriptor( "verbose",
                                  "Run command in verbose mode",
                                  new int[]{QUIET_OPT} ),
          new CLOptionDescriptor( "quiet",
                                  "Run command in quiet mode",
                                  new int[]{VERBOSE_OPT} )
      public static void main( final String[] args )
          System.out.println( "Starting IncompatOptions..." );
          System.out.println( CLUtil.describeOptions( OPTIONS ) );
          // Parse the arguments
          final CLArgsParser parser = new CLArgsParser( args, OPTIONS );
          //Make sure that there was no errors parsing
          if( null != parser.getErrorString() )
              System.err.println( "Error: " + parser.getErrorString() );
          // Get a list of parsed options
          final List options = parser.getArguments();
          final int size = options.size();
          for( int i = 0; i < size; i++ )
              final CLOption option = (CLOption)options.get( i );
              switch( option.getId() )
                  case CLOption.TEXT_ARGUMENT:
                      //This occurs when a user supplies an argument that
                      //is not an option
                      System.out.println( "Unknown arg: " + option.getArgument() );
                  case VERBOSE_OPT:
                      System.out.println( "Verbose mode!" );
                  case QUIET_OPT:
                      System.out.println( "Quiet mode!" );
  1.1                  jakarta-avalon-excalibur/cli/examples/incompat_options/README.txt
  Index: README.txt
  Welcome to Excalibur CLI!
  As always, the if you have any questions :
  1) Make sure you followed any directions
  2) Review documentation included in this package, or online at
  3) Ask on the avalon-dev list.  This is a great source of support
     information. To join, read http://jakarta.apache.org/site/mail.html
     and then follow the link at the bottom to join the lists.
  This simple example shows how to make options incompatible with one another.
  In the application it demonstrates how to make two command line options
  (quiet and verbose) incompatible with each other.
  Compile it by running
  javac -classpath ../../build/lib/@dist.name@.jar *.java (Unix)
  javac -classpath ..\..\build\lib\@dist.name@.jar *.java (Windows)
  Run it using the scripts provided:
    java -classpath ../../build/lib/@dist.name@.jar:. IncompatOptions (Unix)
    java -classpath ..\..\build\lib\@dist.name@.jar;. IncompatOptions (Windows)
  Try passing both quiet and verbose options to the command.

To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>

View raw message