summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/cli
diff options
context:
space:
mode:
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/cli')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommand.java9
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommandMode.java26
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/cli/ICommandHelp.java5
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/cli/ICommandMode.java21
4 files changed, 31 insertions, 30 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommand.java b/BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommand.java
index 1a95018..e73d936 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommand.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommand.java
@@ -24,14 +24,15 @@ public class GenericCommand implements ICommand {
*/
public GenericCommand(ICommandHandler handler, String description,
String help) {
- if(handler == null) {
- throw new NullPointerException("Command handler must not be null");
+ if (handler == null) {
+ throw new NullPointerException(
+ "Command handler must not be null");
}
-
+
this.handler = handler;
this.help = new GenericHelp(description, help);
}
-
+
@Override
public ICommand aliased() {
return new DelegatingCommand(this);
diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommandMode.java b/BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommandMode.java
index 59d3dc3..4b3b4fd 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommandMode.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommandMode.java
@@ -21,24 +21,24 @@ public class GenericCommandMode implements ICommandMode {
/*
* Contains the commands this mode handles
*/
- private IMap<String, ICommand> commandHandlers;
- private IMap<String, ICommand> defaultHandlers;
+ private IMap<String, ICommand> commandHandlers;
+ private IMap<String, ICommand> defaultHandlers;
// Contains help topics without an associated command
- private IMap<String, ICommandHelp> helpTopics;
+ private IMap<String, ICommandHelp> helpTopics;
// The action to execute upon encountering an unknown command
- private BiConsumer<String, String[]> unknownCommandHandler;
+ private BiConsumer<String, String[]> unknownCommandHandler;
// The functions to use for input/output
- private Consumer<String> errorOutput;
- private Consumer<String> normalOutput;
+ private Consumer<String> errorOutput;
+ private Consumer<String> normalOutput;
// The name of this command mode, or null if it is unnamed
- private String modeName;
+ private String modeName;
// The custom prompt to use, or null if none is specified
- private String customPrompt;
+ private String customPrompt;
/**
* Create a new generic command mode
@@ -332,6 +332,11 @@ public class GenericCommandMode implements ICommandMode {
}
@Override
+ public boolean isCustomPromptEnabled() {
+ return customPrompt != null;
+ }
+
+ @Override
public ICommandMode process(String command, String[] args) {
normalOutput.accept("\n");
@@ -414,9 +419,4 @@ public class GenericCommandMode implements ICommandMode {
defaultHandlers.put("exit", buildExitCommand());
}
-
- @Override
- public boolean isCustomPromptEnabled() {
- return customPrompt != null;
- }
} \ No newline at end of file
diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/ICommandHelp.java b/BJC-Utils2/src/main/java/bjc/utils/cli/ICommandHelp.java
index bd81537..472d6a3 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/cli/ICommandHelp.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/cli/ICommandHelp.java
@@ -18,8 +18,9 @@ public interface ICommandHelp {
* Get the summary line for a command.
*
* A summary line should consist of a string of the following format
- * "<command-name>\t<command-summary>"
- * where anything in angle brackets should be filled in.
+ * "<command-name>\t<command-summary>" where anything in angle brackets
+ * should be filled in.
+ *
* @return The summary line line for a command
*/
public String getSummary();
diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/ICommandMode.java b/BJC-Utils2/src/main/java/bjc/utils/cli/ICommandMode.java
index f60e571..8583b80 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/cli/ICommandMode.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/cli/ICommandMode.java
@@ -44,6 +44,15 @@ public interface ICommandMode {
}
/**
+ * Check if this mode uses a custom prompt
+ *
+ * @return Whether or not this mode uses a custom prompt
+ */
+ public default boolean isCustomPromptEnabled() {
+ return false;
+ }
+
+ /**
* Process a command in this mode
*
* @param command
@@ -53,17 +62,7 @@ public interface ICommandMode {
* @return The command mode to use for the next command. Defaults to
* returning this, and doing nothing else
*/
- public default ICommandMode process(String command,
- String[] args) {
+ public default ICommandMode process(String command, String[] args) {
return this;
}
-
- /**
- * Check if this mode uses a custom prompt
- *
- * @return Whether or not this mode uses a custom prompt
- */
- public default boolean isCustomPromptEnabled() {
- return false;
- }
}