1 /*
2
3 dsh-commandline Command line parser based on typed arguments.
4 Copyright (c) 2004-2012 held jointly by the individual authors.
5
6 This library is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 3 of the License, or (at
9 your option) any later version.
10
11 This library is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with this library; if not, write to the Free Software Foundation,
18 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19
20 > http://www.fsf.org/licensing/licenses/lgpl.html
21 > http://www.opensource.org/licenses/lgpl-license.php
22
23 */
24 package org.dishevelled.commandline;
25
26 /**
27 * A typed argument.
28 *
29 * @param <E> argument type
30 * @author Michael Heuer
31 * @version $Revision: 1059 $ $Date: 2012-01-03 14:03:02 -0600 (Tue, 03 Jan 2012) $
32 */
33 public interface Argument<E>
34 {
35
36 /**
37 * Visit the specified argument string from the specified command line.
38 *
39 * <p>Previous and next argument strings in the command line may be interrogated
40 * by this argument, but the <i>cursor position</i> of the command line must
41 * be reset to what it was at the beginning of this method invocation.</p>
42 *
43 * @param s current argument string
44 * @param commandLine command line to visit
45 * @throws Exception if any error occurs
46 */
47 void visit(String s, CommandLine commandLine)
48 throws Exception;
49
50 /**
51 * Return the short name of this argument.
52 *
53 * @return the short name of this argument
54 */
55 String getShortName();
56
57 /**
58 * Return the long name of this argument.
59 *
60 * @return the long name of this argument
61 */
62 String getLongName();
63
64 /**
65 * Return the description of this argument.
66 *
67 * @return the description of this argument
68 */
69 String getDescription();
70
71 /**
72 * Return true if this argument is required.
73 *
74 * @return true if this argument is required
75 */
76 boolean isRequired();
77
78 /**
79 * Return true if this argument was found in the
80 * command line, false if it was not found or if
81 * this argument has not visited a command line
82 * yet.
83 *
84 * @see #visit(String, CommandLine)
85 * @return true if this argument was found in the
86 * command line
87 */
88 boolean wasFound();
89
90 /**
91 * Return the value of this argument.
92 *
93 * @return the value of this argument
94 */
95 E getValue();
96
97 /**
98 * Return the value of this argument or the specified default value
99 * if this argument was not found in the command line.
100 *
101 * @return the value of this argument or the specified default value
102 * if this argument was not found in the command line
103 */
104 E getValue(E defaultValue);
105 }