1- /**
2- * Copyright 2003-2004 The Apache Software Foundation
1+ /*
2+ * Copyright 2003-2005 The Apache Software Foundation
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
2121import org .apache .commons .cli2 .Argument ;
2222import org .apache .commons .cli2 .Group ;
2323import org .apache .commons .cli2 .option .Command ;
24+ import org .apache .commons .cli2 .resource .ResourceConstants ;
25+ import org .apache .commons .cli2 .resource .ResourceHelper ;
2426
2527/**
2628 * Builds Command instances
2729 */
2830public class CommandBuilder {
29-
3031 /** the preferred name of the command */
3132 private String preferredName ;
3233
@@ -58,26 +59,18 @@ public CommandBuilder() {
5859 /**
5960 * Creates a new <code>Command</code> instance using the properties of the
6061 * <code>CommandBuilder</code>.
61- *
62+ *
6263 * @return the new Command instance
6364 */
6465 public Command create () {
65-
6666 // check we have a valid name
6767 if (preferredName == null ) {
68- throw new IllegalStateException ("Options must have at least one name" );
68+ throw new IllegalStateException (ResourceHelper . getResourceHelper (). getMessage ( ResourceConstants . OPTION_NO_NAME ) );
6969 }
7070
7171 // build the command
7272 final Command option =
73- new Command (
74- preferredName ,
75- description ,
76- aliases ,
77- required ,
78- argument ,
79- children ,
80- id );
73+ new Command (preferredName , description , aliases , required , argument , children , id );
8174
8275 // reset the builder
8376 reset ();
@@ -86,8 +79,8 @@ public Command create() {
8679 }
8780
8881 /**
89- * Resets the CommandBuilder to the defaults for a new Command.
90- *
82+ * Resets the CommandBuilder to the defaults for a new Command.
83+ *
9184 * This method is called automatically at the end of the
9285 * {@link #create() create} method.
9386 */
@@ -99,24 +92,24 @@ public CommandBuilder reset() {
9992 argument = null ;
10093 children = null ;
10194 id = 0 ;
95+
10296 return this ;
10397 }
10498
10599 /**
106- * Specifies the name for the next <code>Command</code>
100+ * Specifies the name for the next <code>Command</code>
107101 * that is created. The first name is used as the preferred
108- * display name for the <code>Command</code> and then
102+ * display name for the <code>Command</code> and then
109103 * later names are used as aliases.
110- *
104+ *
111105 * @param name the name for the next <code>Command</code>
112106 * that is created.
113107 * @return this <code>CommandBuilder</code>.
114108 */
115109 public CommandBuilder withName (final String name ) {
116110 if (preferredName == null ) {
117111 preferredName = name ;
118- }
119- else {
112+ } else {
120113 aliases .add (name );
121114 }
122115
@@ -125,15 +118,16 @@ public CommandBuilder withName(final String name) {
125118
126119 /**
127120 * Specifies the description for the next <code>Command</code>
128- * that is created. This description is used to produce
121+ * that is created. This description is used to produce
129122 * help documentation for the <code>Command</code>.
130- *
131- * @param newDescription the description for the next
123+ *
124+ * @param newDescription the description for the next
132125 * <code>Command</code> that is created.
133126 * @return this <code>CommandBuilder</code>.
134127 */
135128 public CommandBuilder withDescription (final String newDescription ) {
136129 this .description = newDescription ;
130+
137131 return this ;
138132 }
139133
@@ -146,43 +140,47 @@ public CommandBuilder withDescription(final String newDescription) {
146140 */
147141 public CommandBuilder withRequired (final boolean newRequired ) {
148142 this .required = newRequired ;
143+
149144 return this ;
150145 }
151146
152147 /**
153- * Specifies the children for the next <code>Command</code>
148+ * Specifies the children for the next <code>Command</code>
154149 * that is created.
155- *
150+ *
156151 * @param newChildren the child options for the next <code>Command</code>
157152 * that is created.
158153 * @return this <code>CommandBuilder</code>.
159154 */
160155 public CommandBuilder withChildren (final Group newChildren ) {
161156 this .children = newChildren ;
157+
162158 return this ;
163159 }
164160
165161 /**
166- * Specifies the argument for the next <code>Command</code>
162+ * Specifies the argument for the next <code>Command</code>
167163 * that is created.
168- *
169- * @param newArgument the argument for the next <code>Command</code>
164+ *
165+ * @param newArgument the argument for the next <code>Command</code>
170166 * that is created.
171167 * @return this <code>CommandBuilder</code>.
172168 */
173169 public CommandBuilder withArgument (final Argument newArgument ) {
174170 this .argument = newArgument ;
171+
175172 return this ;
176173 }
177174
178175 /**
179176 * Specifies the id for the next <code>Command</code> that is created.
180- *
177+ *
181178 * @param newId the id for the next <code>Command</code> that is created.
182179 * @return this <code>CommandBuilder</code>.
183180 */
184181 public final CommandBuilder withId (final int newId ) {
185182 this .id = newId ;
183+
186184 return this ;
187185 }
188186}
0 commit comments