View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.cli2;
18  
19  import java.util.List;
20  
21  /**
22   * A CommandLine that detected values and options can be written to.
23   */
24  public interface WriteableCommandLine extends CommandLine {
25  
26      /**
27       * Adds an Option to the CommandLine
28       * @param option the Option to add
29       */
30      void addOption(final Option option);
31  
32      /**
33       * Adds a value to an Option in the CommandLine.
34       * @param option the Option to add to
35       * @param value the value to add
36       */
37      void addValue(final Option option, final Object value);
38  
39      /**
40       * Retrieves the Argument values specified on the command line for the
41       * specified Option, this doesn't return any values supplied
42       * programmatically as defaults.
43       *
44       * @param option the Option associated with the values
45       * @return a list of values or an empty List if none are found
46       */
47      List getUndefaultedValues(final Option option);
48  
49      /**
50       * Sets the default values for an Option in the CommandLine
51       * @param option the Option to add to
52       * @param defaultValues the defaults for the option
53       */
54      void setDefaultValues(final Option option, final List defaultValues);
55  
56      /**
57       * Adds a switch value to an Option in the CommandLine.
58       * @param option the Option to add to
59       * @param value the switch value to add
60       * @throws IllegalStateException if the switch has already been added
61       */
62      void addSwitch(final Option option, final boolean value) throws IllegalStateException;
63  
64      /**
65       * Sets the default state for a Switch in the CommandLine.
66       * @param option the Option to add to
67       * @param defaultSwitch the defaults state for ths switch
68       */
69      void setDefaultSwitch(final Option option, final Boolean defaultSwitch);
70  
71      /**
72       * Adds a property value to a name in the CommandLine.
73       * Replaces any existing value for the property.
74       *
75       * @param option the Option to add to
76       * @param property the name of the property
77       * @param value the value of the property
78       */
79      void addProperty(final Option option, final String property, final String value);
80  
81      /**
82       * Adds a property value to the default property set.
83       * Replaces any existing value for the property.
84       *
85       * @param property the name of the property
86       * @param value the value of the property
87       */
88      void addProperty(final String property, final String value);
89  
90      /**
91       * Detects whether the argument looks like an Option trigger
92       * @param argument the argument to test
93       * @return true if the argument looks like an Option trigger
94       */
95      boolean looksLikeOption(final String argument);
96  
97      /**
98       * Returns the option that is currently processed.
99       *
100      * @return the current option
101      */
102     Option getCurrentOption();
103 
104     /**
105      * Sets the current option. This method is called by concrete option
106      * implementations during command line processing. It enables the command
107      * line to keep track about the option that is currently processed.
108      *
109      * @param currentOption the new current option
110      */
111     void setCurrentOption(Option currentOption);
112 }