summaryrefslogtreecommitdiff
path: root/base/src/main/java/bjc/utils/cli/objects/Command.java
diff options
context:
space:
mode:
Diffstat (limited to 'base/src/main/java/bjc/utils/cli/objects/Command.java')
-rw-r--r--base/src/main/java/bjc/utils/cli/objects/Command.java84
1 files changed, 77 insertions, 7 deletions
diff --git a/base/src/main/java/bjc/utils/cli/objects/Command.java b/base/src/main/java/bjc/utils/cli/objects/Command.java
index e605a2b..3a7d452 100644
--- a/base/src/main/java/bjc/utils/cli/objects/Command.java
+++ b/base/src/main/java/bjc/utils/cli/objects/Command.java
@@ -1,8 +1,15 @@
package bjc.utils.cli.objects;
+/**
+ * A single-line command read from the user.
+ *
+ * @author Ben Culkin
+ */
public class Command {
/**
* Command status values.
+ *
+ * @author Ben Culkin
*/
public static enum CommandStatus {
/**
@@ -23,21 +30,38 @@ public class Command {
FINISH,
}
+ /**
+ * The line number of this command.
+ */
public final int lineNo;
+ /**
+ * The full text of this command.
+ */
public final String fullCommand;
+ /**
+ * The text of this command without its name.
+ */
public final String remnCommand;
+ /**
+ * The name of this command.
+ */
public final String nameCommand;
+ /**
+ * The name of the I/O source this command was read from.
+ */
public final String ioSource;
/**
* Create a new command.
*
* @param ln
- * The line to get the command from.
+ * The string to get the command from.
+ *
* @param lno
* The number of the line the command came from.
+ *
* @param ioSrc
* The name of where the I/O came from.
*/
@@ -55,16 +79,28 @@ public class Command {
ioSource = ioSrc;
}
+ /**
+ * Parse a command from a string.
+ *
+ * The main thing this does is ignore blank lines, as well as comments
+ * marked by #'s either at the start of the line or part of the way
+ * through the line.
+ *
+ * @param ln
+ * The string to get the command from.
+ *
+ * @param lno
+ * The line number of the command.
+ *
+ * @param ioSource
+ * The name of where the I/O came from.
+ */
public static Command fromString(String ln, int lno, String ioSource) {
- /*
- * Ignore blank lines and comments.
- */
+ /* Ignore blank lines and comments. */
if(ln.equals("")) return null;
if(ln.startsWith("#")) return null;
- /*
- * Trim off comments part-way through the line.
- */
+ /* Trim off comments part-way through the line. */
int idxHash = ln.indexOf('#');
if(idxHash != -1) {
ln = ln.substring(0, idxHash).trim();
@@ -73,12 +109,46 @@ public class Command {
return new Command(ln, lno, ioSource);
}
+ /**
+ * Give an informational message about something in relation to this
+ * command.
+ *
+ * @param info
+ * The informational message.
+ *
+ * @param parms
+ * The parameters for the informational message.
+ */
+ public String info(String info, Object... parms) {
+ String msg = String.format(info, parms);
+
+ return String.format("INFO (%s:%d): %s", ioSource, lineNo, msg);
+ }
+
+ /**
+ * Warn about something in relation to this command.
+ *
+ * @param warning
+ * The warning message.
+ *
+ * @param parms
+ * The parameters for the warning message.
+ */
public String warn(String warning, Object... parms) {
String msg = String.format(warning, parms);
return String.format("WARNING (%s:%d): %s", ioSource, lineNo, msg);
}
+ /**
+ * Give an error about something in relation to this command.
+ *
+ * @param error
+ * The error message.
+ *
+ * @param parms
+ * The parameters for the error message.
+ */
public String error(String err, Object... parms) {
String msg = String.format(err, parms);