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/no_aliasing NoAlias.java README.txt
Date Tue, 19 Mar 2002 10:50:11 GMT
donaldp     02/03/19 02:50:11

  Added:       cli/examples/no_aliasing NoAlias.java README.txt
  Log:
  Add no alias example
  
  Revision  Changes    Path
  1.1                  jakarta-avalon-excalibur/cli/examples/no_aliasing/NoAlias.java
  
  Index: NoAlias.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;
  
  /**
   * This simple example shows how to set it up so that only the
   * long form or only short form of an option is capable of
   * being used.
   *
   * @author <a href="peter@apache.org">Peter Donald</a>
   */
  public class NoAlias
  {
      // Define our short one-letter option identifiers.
      private static final int SHORT_OPT = 's';
      private static final int LONG_OPT = 1;
  
      private static final CLOptionDescriptor[] OPTIONS = new CLOptionDescriptor[]
      {
          new CLOptionDescriptor( null,
                                  CLOptionDescriptor.ARGUMENT_DISALLOWED,
                                  SHORT_OPT,
                                  "option with only short form",
                                  new int[ 0 ] ),
          new CLOptionDescriptor( "long",
                                  CLOptionDescriptor.ARGUMENT_DISALLOWED,
                                  LONG_OPT,
                                  "option with long form" )
      };
  
      public static void main( final String[] args )
      {
          System.out.println( "Starting NoAlias..." );
          System.out.println( CLUtil.describeOptions( OPTIONS ) );
          System.out.println();
  
          // Parse the arguments
          final CLArgsParser parser = new CLArgsParser( args, OPTIONS );
  
          //Make sure that there was no errors parsing
          //arguments
          if( null != parser.getErrorString() )
          {
              System.err.println( "Error: " + parser.getErrorString() );
              return;
          }
  
          // 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() );
                      break;
  
                  case SHORT_OPT:
                      System.out.println( "Received short option" );
                      break;
  
                  case LONG_OPT:
                      System.out.println( "Received long option" );
                      break;
              }
          }
      }
  }
  
  
  1.1                  jakarta-avalon-excalibur/cli/examples/no_aliasing/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
        http://jakarta.apache.org/avalon/excalibur
  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.
  
  noalias
  -------
  This simple example shows how to set it up so that only the long form
  or only short form of an option is capable of being used.
  
  Compile it by running
  
  javac -classpath ../../build/lib/@dist.name@.jar *.java (Unix)
  
  or
  
  javac -classpath ..\..\build\lib\@dist.name@.jar *.java (Windows)
  
  Run it using the scripts provided:
  
    java -classpath ../../build/lib/@dist.name@.jar:. NoAlias (Unix)
  
  or
  
    java -classpath ..\..\build\lib\@dist.name@.jar;. NoAlias (Windows)
  
  
  Try passing it the "--help" command line option to see which other
  command line options are available. The experiment by passing in
  different options.
  
  Some combinations to try out include
  
  --help
  -h
  h
  --version
  
  
  

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


Mime
View raw message