donaldp     2002/09/12 03:32:30

  Modified:    cli/src/java/org/apache/avalon/excalibur/cli
                        CLArgsParser.java CLOption.java
                        CLOptionDescriptor.java
  Log:
  Exposed the descriptor via the CLOption.
  
  Submitted By: [EMAIL PROTECTED] (Torsten Knodt)
  PR: 12545
  
  Revision  Changes    Path
  1.21      +2 -2      
jakarta-avalon-excalibur/cli/src/java/org/apache/avalon/excalibur/cli/CLArgsParser.java
  
  Index: CLArgsParser.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/cli/src/java/org/apache/avalon/excalibur/cli/CLArgsParser.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- CLArgsParser.java 7 Aug 2002 05:45:02 -0000       1.20
  +++ CLArgsParser.java 12 Sep 2002 10:32:28 -0000      1.21
  @@ -599,7 +599,7 @@
           }
   
           m_state = getStateFor( descriptor );
  -        m_option = new CLOption( descriptor.getId() );
  +        m_option = new CLOption( descriptor );
   
           if( STATE_NORMAL == m_state )
           {
  
  
  
  1.11      +31 -25    
jakarta-avalon-excalibur/cli/src/java/org/apache/avalon/excalibur/cli/CLOption.java
  
  Index: CLOption.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/cli/src/java/org/apache/avalon/excalibur/cli/CLOption.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- CLOption.java     7 Aug 2002 05:45:02 -0000       1.10
  +++ CLOption.java     12 Sep 2002 10:32:28 -0000      1.11
  @@ -23,29 +23,8 @@
        */
       public static final int TEXT_ARGUMENT = 0;
   
  -    private final int m_id;
       private String[] m_arguments;
  -
  -    /**
  -     * Constructor taking an id (that must be a proper character code)
  -     *
  -     * @param id the new id
  -     */
  -    public CLOption( final int id )
  -    {
  -        m_id = id;
  -    }
  -
  -    /**
  -     * Constructor taking argument for option.
  -     *
  -     * @param argument the argument
  -     */
  -    public CLOption( final String argument )
  -    {
  -        this( TEXT_ARGUMENT );
  -        addArgument( argument );
  -    }
  +    private CLOptionDescriptor m_descriptor;
   
       /**
        * Retrieve argument to option if it takes arguments.
  @@ -82,10 +61,37 @@
        * The id is eqivalent to character code if it can be a single letter option.
        *
        * @return the id
  +     * @deprecated use <code>getDescriptor().getId()</code> instead
        */
       public final int getId()
       {
  -        return m_id;
  +        return m_descriptor == null ? TEXT_ARGUMENT : m_descriptor.getId();
  +    }
  +
  +    public final CLOptionDescriptor getDescriptor()
  +    {
  +        return m_descriptor;
  +    }
  +
  +    /**
  +     * Constructor taking an descriptor
  +     *
  +     * @param descriptor the descriptor
  +     */
  +    public CLOption( final CLOptionDescriptor descriptor )
  +    {
  +        m_descriptor = descriptor;
  +    }
  +
  +    /**
  +     * Constructor taking argument for option.
  +     *
  +     * @param argument the argument
  +     */
  +    public CLOption( final String argument )
  +    {
  +        this( (CLOptionDescriptor) null );
  +        addArgument( argument );
       }
   
       /**
  @@ -134,7 +140,7 @@
       {
           final StringBuffer sb = new StringBuffer();
           sb.append( "[Option " );
  -        sb.append( (char)m_id );
  +        sb.append( (char)m_descriptor.getId() );
   
           if( null != m_arguments )
           {
  
  
  
  1.15      +29 -4     
jakarta-avalon-excalibur/cli/src/java/org/apache/avalon/excalibur/cli/CLOptionDescriptor.java
  
  Index: CLOptionDescriptor.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/cli/src/java/org/apache/avalon/excalibur/cli/CLOptionDescriptor.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- CLOptionDescriptor.java   7 Aug 2002 05:45:02 -0000       1.14
  +++ CLOptionDescriptor.java   12 Sep 2002 10:32:28 -0000      1.15
  @@ -62,19 +62,20 @@
        * @param flags the flags
        * @param id the id/character option
        * @param description description of option usage
  -     * @param incompatable an array listing the ids of all incompatible options
  +     * @param incompatible an array listing the ids of all incompatible options
  +     * @deprecated use the version with the array of CLOptionDescriptor's
        */
       public CLOptionDescriptor( final String name,
                                  final int flags,
                                  final int id,
                                  final String description,
  -                               final int[] incompatable )
  +                               final int[] incompatible )
       {
           m_id = id;
           m_name = name;
           m_flags = flags;
           m_description = description;
  -        m_incompatible = incompatable;
  +        m_incompatible = incompatible;
   
           int modeCount = 0;
           if( ( ARGUMENT_REQUIRED & flags ) == ARGUMENT_REQUIRED )
  @@ -104,6 +105,30 @@
               final String message = "Multiple modes specified for option " + this;
               throw new IllegalStateException( message );
           }
  +    }
  +
  +    /**
  +     * Constructor.
  +     *
  +     * @param name the name/long option
  +     * @param flags the flags
  +     * @param id the id/character option
  +     * @param description description of option usage
  +     */
  +    public CLOptionDescriptor( final String name,
  +                               final int flags,
  +                               final int id,
  +                               final String description,
  +                               final CLOptionDescriptor[] incompatible )
  +    {
  +        m_id = id;
  +        m_name = name;
  +        m_flags = flags;
  +        m_description = description;
  +
  +     m_incompatible = new int[incompatible.length];
  +     for (int i = 0; i < incompatible.length; i++)
  +         m_incompatible[i] = incompatible[i].getId();
       }
   
       /**
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to