Adapted applications to make only attachement to the framework
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* gclc:fr.bigeon.gclc.ApplicationAttachement.java
|
||||
* Created on: Apr 19, 2017
|
||||
*/
|
||||
package fr.bigeon.gclc;
|
||||
|
||||
import fr.bigeon.gclc.exception.InvalidCommandName;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* TODO
|
||||
*
|
||||
* @author Emmanuel Bigeon
|
||||
*
|
||||
*/
|
||||
public interface ApplicationAttachement {
|
||||
/** Attach this object to a console application.
|
||||
* <p>
|
||||
* The attaching usually consist in the addition of commands in the console
|
||||
* application. The attached command should be specific to the attachement
|
||||
* (typically, the generic help command or the script command should not be
|
||||
* added through this mechanism).
|
||||
*
|
||||
* @param application the application
|
||||
* @throws InvalidCommandName if a command name is invalid for the
|
||||
* application. */
|
||||
void attach(ConsoleApplication application) throws InvalidCommandName;
|
||||
}
|
||||
@@ -73,19 +73,19 @@ import fr.bigeon.gclc.manager.ConsoleManager;
|
||||
* start method.
|
||||
*
|
||||
* @author Emmanuel BIGEON */
|
||||
public class ConsoleApplication implements ICommandProvider {
|
||||
public final class ConsoleApplication implements ICommandProvider {
|
||||
|
||||
/** The class logger */
|
||||
private static final Logger LOGGER = Logger
|
||||
.getLogger(ConsoleApplication.class.getName());
|
||||
/** The welcome message */
|
||||
private final String header;
|
||||
public final String header;
|
||||
/** The good bye message */
|
||||
private final String footer;
|
||||
public final String footer;
|
||||
/** The console manager */
|
||||
protected final ConsoleManager manager;
|
||||
public final ConsoleManager manager;
|
||||
/** The container of commands */
|
||||
private final SubedCommand root;
|
||||
public final SubedCommand root;
|
||||
/** The state of this application */
|
||||
private boolean running;
|
||||
/** The listeners */
|
||||
@@ -135,11 +135,6 @@ public class ConsoleApplication implements ICommandProvider {
|
||||
return root.get(command);
|
||||
}
|
||||
|
||||
/** @return the manager */
|
||||
public final ConsoleManager getManager() {
|
||||
return manager;
|
||||
}
|
||||
|
||||
/** @param cmd the command
|
||||
* @throws IOException if the command could not be parsed */
|
||||
public final void interpretCommand(String cmd) throws IOException {
|
||||
@@ -161,7 +156,7 @@ public class ConsoleApplication implements ICommandProvider {
|
||||
.getString("ConsoleApplication.cmd.failed", cmd)); //$NON-NLS-1$
|
||||
manager.println(e.getLocalizedMessage());
|
||||
if (e.getType() == CommandRunExceptionType.USAGE) {
|
||||
e.getSource().help(getManager());
|
||||
e.getSource().help(manager);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -247,19 +242,4 @@ public class ConsoleApplication implements ICommandProvider {
|
||||
public boolean isRunning() {
|
||||
return running;
|
||||
}
|
||||
|
||||
/** @return the root */
|
||||
public SubedCommand getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
/** @return the header */
|
||||
public String getHeader() {
|
||||
return header;
|
||||
}
|
||||
|
||||
/** @return the footer */
|
||||
public String getFooter() {
|
||||
return footer;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,4 +184,11 @@ public class CommandParameters {
|
||||
public Set<String> getStringArgumentKeys() {
|
||||
return stringArguments.keySet();
|
||||
}
|
||||
|
||||
/** @param key the key
|
||||
* @return if the key is present in string arguments or boolean ones. */
|
||||
public boolean hasArgument(String key) {
|
||||
return stringArguments.containsKey(key) ||
|
||||
booleanArguments.containsKey(key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,9 +247,10 @@ public abstract class ParametrizedCommand extends Command {
|
||||
for (final String string : toProvide) {
|
||||
String value;
|
||||
try {
|
||||
value = manager.prompt(string);
|
||||
value = manager.prompt("value of " + string + "? ");
|
||||
while (value.isEmpty()) {
|
||||
value = manager.prompt(string);
|
||||
value = manager.prompt(
|
||||
"value of " + string + "? (cannot be empty) ");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new CommandRunException(
|
||||
|
||||
Reference in New Issue
Block a user