View Javadoc

1   /*
2    VerboseOption.java
3    Creation date : 2/06/2010
4    Copyright © Benjamin Croizet (graffity2199@yahoo.fr)
5   
6    This program is free software; you can redistribute it and/or
7    modify it under the terms of the GNU General Public License
8    or GNU Lesser General Public License as published by the
9    Free Software Foundation; either version 3 of the License,
10   or (at your option) any later version.
11  
12   This program is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16  
17   You should have received copies of the GNU General Public License
18   and GNU Lesser General Public License along with this program;
19   if not, write to the Free Software Foundation, Inc.,
20   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21   http://www.fsf.org/licensing/licenses/gpl.html
22   http://www.gnu.org/licenses/lgpl.html
23   */
24  
25  package net.sourceforge.plantumldependency.commoncli.option.impl.verbose;
26  
27  import static java.util.Arrays.asList;
28  import static java.util.Collections.unmodifiableSet;
29  import static net.sourceforge.plantumldependency.common.utils.check.ParameterCheckerUtils.checkNull;
30  import static net.sourceforge.plantumldependency.commoncli.constants.log.ErrorConstants.COMMAND_LINE_NULL_ERROR;
31  import static net.sourceforge.plantumldependency.commoncli.option.status.OptionStatus.ACTIVE_OPTIONAL_OPTION_STATUS;
32  
33  import java.util.Set;
34  import java.util.TreeSet;
35  
36  import net.sourceforge.plantumldependency.commoncli.command.CommandLine;
37  import net.sourceforge.plantumldependency.commoncli.exception.CommandLineException;
38  import net.sourceforge.plantumldependency.commoncli.option.AbstractOption;
39  import net.sourceforge.plantumldependency.commoncli.option.status.OptionStatus;
40  
41  /**
42   * A default implementation managing the "-verbose" option, allowing to set the program debug
43   * option. <i>Note : no option should have the same main or secondary names</i>.
44   *
45   * @author Benjamin Croizet (<a href="mailto:graffity2199@yahoo.fr>graffity2199@yahoo.fr</a>)
46   * @since 1.3.0
47   * @version 1.3.0
48   */
49  public class VerboseOption extends AbstractOption {
50  
51      /** Serial version UID. */
52      private static final long serialVersionUID = -5847253494029333067L;
53  
54      /** Option main synopsis. */
55      public static final String OPTION_MAIN_SYNOPSIS = "-v";
56  
57      /** Option synopsis alias. */
58      public static final Set < String > OPTION_SYNOPSIS = unmodifiableSet(new TreeSet < String >(
59              asList(new String[] {"--verbose"})));
60  
61      /**
62       * Default constructor.
63       *
64       * @since 1.3.0
65       */
66      public VerboseOption() {
67          this(new StringBuilder("To display log information."), ACTIVE_OPTIONAL_OPTION_STATUS);
68      }
69  
70      /**
71       * Full constructor.
72       *
73       * @param fullOptionDescription
74       *            the full option usage description, explaining what the option does (used for
75       *            helping message). <i>Note : a new {@link StringBuilder} is created.</i>
76       * @param optionStatus
77       *            the option status, telling if the option is active, inactive or hidden, mustn't be
78       *            <code>null</code>.
79       * @since 1.3.0
80       */
81      public VerboseOption(final StringBuilder fullOptionDescription, final OptionStatus optionStatus) {
82          super("-v", unmodifiableSet(new TreeSet < String >(asList(new String[] {"--verbose"}))), fullOptionDescription,
83                  optionStatus);
84      }
85  
86      /**
87       * {@inheritDoc}
88       *
89       * @since 1.3.0
90       */
91      @Override
92      public VerboseOption deepClone() {
93          return (VerboseOption) super.deepClone();
94      }
95  
96      /**
97       * {@inheritDoc}
98       *
99       * @since 1.3.0
100      */
101     @Override
102     protected StringBuilder getFullUsageAdditions() {
103         return new StringBuilder();
104     }
105 
106     /**
107      * {@inheritDoc}
108      *
109      * @since 1.3.0
110      */
111     @Override
112     protected StringBuilder getFullUsageDescriptionAdditions() {
113         return new StringBuilder();
114     }
115 
116     /**
117      * {@inheritDoc}
118      *
119      * @since 1.3.0
120      */
121     @Override
122     protected StringBuilder getMainUsageAdditions() {
123         return new StringBuilder();
124     }
125 
126     /**
127      * Read and parses the command to see if the verbose option has been specified.
128      *
129      * @param commandLine
130      *            the {@link CommandLine} instance to read and parse, mustn't be <code>null</code>.
131      * @return <code>true</code> if the verbose option has been specified, <code>false</code>
132      *         otherwise.
133      * @throws CommandLineException
134      *             if any error occurs when reading or parsing the command line.
135      * @since 1.3.0
136      */
137     public boolean isVerboseModeActive(final CommandLine commandLine) throws CommandLineException {
138         checkNull(commandLine, COMMAND_LINE_NULL_ERROR);
139 
140         return commandLine.isOptionActiveAndSpecified(this);
141     }
142 }