1 /* 2 CommandLine.java 3 Creation date : 11/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.command; 26 27 import java.io.Serializable; 28 import java.util.List; 29 30 import net.sourceforge.plantumldependency.common.clone.DeepCloneable; 31 import net.sourceforge.plantumldependency.commoncli.exception.CommandLineException; 32 import net.sourceforge.plantumldependency.commoncli.option.Option; 33 import net.sourceforge.plantumldependency.commoncli.option.OptionWithArgument; 34 35 /** 36 * The interface which describes a command line, gathering the list of all arguments passed to a 37 * program. 38 * 39 * @author Benjamin Croizet (<a href="mailto:graffity2199@yahoo.fr>graffity2199@yahoo.fr</a>) 40 * @since 1.3.0 41 * @version 1.3.0 42 */ 43 public interface CommandLine extends Comparable < CommandLine >, Serializable, DeepCloneable < CommandLine > { 44 45 /** 46 * Find and returns the option argument if specified on the command line. 47 * 48 * @param option 49 * the option to look for, mustn't be <code>null</code>. 50 * @return the option argument as a {@link String} if found, the 51 * {@link net.sourceforge.plantumldependency.common.constants.CommonConstants#BLANK_STRING} 52 * if the option is specified on the command line without any argument behind, or 53 * <code>null</code> if the option hasn't been specified. 54 * @throws CommandLineException 55 * if any error occurs when finding the option in the command line, for instance 56 * when the option is specified several times in the command line. 57 * @since 1.3.0 58 */ 59 String findOptionArgument(OptionWithArgument < ? > option) throws CommandLineException; 60 61 /** 62 * Gets all command line arguments, without program information. 63 * <p> 64 * For instance it can be :<br> 65 * <i>-a</i><br> 66 * <i>-h</i><br> 67 * <i>-v</i> 68 * </p> 69 * 70 * @return all command line arguments as a {@link List} of {@link String}. 71 * @since 1.3.0 72 */ 73 List < String > getCommandLineArguments(); 74 75 /** 76 * Gets the full command line as a single {@link StringBuilder}, without program information. 77 * <p> 78 * For instance it can be :<br> 79 * <i>-a -h -v</i> 80 * </p> 81 * 82 * @return the {@link StringBuilder} representing the full command line argument. 83 * @since 1.3.0 84 */ 85 StringBuilder getCommandLineArgumentsAsString(); 86 87 /** 88 * Tells if one of the passed option names is active or hidden and is specified in the command 89 * line. 90 * 91 * @param option 92 * the option to look for, mustn't be <code>null</code>. 93 * @return <code>true</code> if one of the option names has been found in the command line and 94 * is active or hidden, <code>false</code> otherwise. 95 * @throws CommandLineException 96 * if any error occurs when reading or parsing the command line, for instance when 97 * the option is specified several times in the command line or if the option isn't 98 * specified while it is mandatory. 99 * @since 1.3.0 100 */ 101 boolean isOptionActiveAndSpecified(Option option) throws CommandLineException; 102 103 /** 104 * Tells if one of the passed option names is specified in the command line, whatever its status 105 * is. 106 * 107 * @param option 108 * the option to look for, mustn't be <code>null</code>. 109 * @return <code>true</code> if one of the option names has been found in the command line, 110 * <code>false</code> otherwise. 111 * @throws CommandLineException 112 * if any error occurs when reading or parsing the command line, for instance when 113 * the option is specified several times in the command line or if the option isn't 114 * specified while it is mandatory. 115 * @since 1.3.0 116 */ 117 boolean isOptionSpecified(Option option) throws CommandLineException; 118 }