From 583d2a97f378ef8c0fdcc128b2e041d413d7ba8f Mon Sep 17 00:00:00 2001 From: pkelaita Date: Wed, 6 Sep 2017 12:14:41 -0700 Subject: [PATCH] updated docs for 1.1 --- CHANGELOG.md | 7 ++++++ README.md | 24 ++++++++++++++++--- examples/ExampleApp.java | 9 ++++--- src/main/java/com/jModule/def/Command.java | 8 +++---- .../java/com/jModule/exec/ConsoleClient.java | 18 ++++++++++++-- src/main/java/com/jModule/util/InputUtil.java | 2 +- 6 files changed, 55 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3677325..e4f785f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## Version 1.1 +### 1.1.0 - 2017-09-06 +- **Added** + - Ability to set command logging + - Ability to toggle between commands +- **Fixed** + - CLI no longer freezes when toggling through commands ## Version 1.0 ### 1.0.3 - 2017-09-05 diff --git a/README.md b/README.md index 4bc6438..42cd2a2 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,23 @@ own JModule applications.   +## What's New in Version 1.1 +JModule 1.1 now supports an accessible command history. To allow your application's users to access their command history, simply +define your console client and then use +```java +yourClient.setHistoryLoggingEnabled(true); +```` +When the user runs your app, they will now be able to toggle through their command history by using the ↑ and ↓ keys. Additionally, +the CLI prompt will display how many commands are stored in its working history. For example, if the user has run 5 different commands, they +will see a prompt as such: +``` +YourAppName: yourmodule 5$ +``` +To see the full list of changes implemented in version 1.1, consult the [Changelog](https://github.com/pkelaita/JModule/blob/master/CHANGELOG.md). +  + +  + ## Writing a JModule application ### Defining your commands Each JModule command runs based on its own command logic. So before you can create a command, you'll have to create a class @@ -125,12 +142,14 @@ staments, module help pages are generated as a standard help page of the style s `yourModule.resetHelpPage(String reset)` and `yourModule.appendHelpPage(String append)`. Now that we've defined our modules, the last step is to implement these modules into a console. This can be accomplished with -the ConsoleClient class. This class is very easy to instantiate; all you need to do is give it a name and home module that -the application can use as a starting point. From there, we can add additional modules and, finally, run the console +the ConsoleClient class. This class is very easy to instantiate; all you need to do is give it a name and a home module that +the application can use as a starting point. From there, we can add additional modules, enable history logging, and finally, run the console application. ```java ConsoleClient client = new ConsoleClient("ExampleEducationApp", math); client.addModule(quiz); +client.setHistoryLoggingEnabled(true); + client.runConsole(); ``` To take an in-depth look at the fully implemented example application, `ExampleApp.java` is outfitted with helpful comments @@ -141,7 +160,6 @@ and defines all its logic classes in the same file for readability. ## Planned future updates * Ability to share data between commands without writing a separate class to store data -* Accessible command history * More flexible parameter options * Separate class for parameters * Support for indefinite parameters diff --git a/examples/ExampleApp.java b/examples/ExampleApp.java index 859c5d2..0b4af31 100644 --- a/examples/ExampleApp.java +++ b/examples/ExampleApp.java @@ -20,22 +20,25 @@ public static void main(String[] args) { // set up commands // 'add' - AddCmdLogic addLogic = new AddCmdLogic(); // set up command logic ArrayList addParams = new ArrayList<>(); // create parameters addParams.add("first number"); addParams.add("second number"); + + AddCmdLogic addLogic = new AddCmdLogic(); // set up command logic addLogic.setParams(addParams); // add parameters to the command logic Command addCmd = new Command("add", "Adds 2 numbers together", addLogic); // set up command with logic // 'subtract' - SubtractCmdLogic subtractLogic = new SubtractCmdLogic(); // set up command logic ArrayList subtractParams = new ArrayList<>(); // create parameters subtractParams.add("first number"); subtractParams.add("second number"); + + SubtractCmdLogic subtractLogic = new SubtractCmdLogic(); // set up command logic subtractLogic.setParams(subtractParams); // add parameters to the command logic + Command subCmd = new Command("subtract", "Subtracts 2 numbers", subtractLogic); // set up command with logic subCmd.addReference("sub"); // add alternate reference to command - subCmd.resetUsage("Usage: the same as above"); + subCmd.resetUsage("Usage: the same as above"); // edit usage with resetUsage() and appendUsage() subCmd.appendUsage("Call this command by typing either 'subtract' or alternatively, 'sub'"); // 'quizme' diff --git a/src/main/java/com/jModule/def/Command.java b/src/main/java/com/jModule/def/Command.java index 3cee0e6..b8d9a94 100644 --- a/src/main/java/com/jModule/def/Command.java +++ b/src/main/java/com/jModule/def/Command.java @@ -6,10 +6,10 @@ /** * Represents a possible command. A command can have multiple references, or * ways to call it from the command line. For example, a "find" command that can - * be accessed by typing 'find' or just 'fd' on the command line. A command can - * also have any number of defined parameters and command-specific logic to - * process the given parameters. - * + * be accessed by typing 'find' or just 'fd' on the command line would have 'fd' + * as an alternate reference. A command can also have any number of defined + * parameters and command-specific logic to process the given parameters. + *

* A command's logic and possible parameters are defined by writing a logic * class extending CommandLogic. For more information about CommandLogic, * consult the CommandLogic documentation diff --git a/src/main/java/com/jModule/exec/ConsoleClient.java b/src/main/java/com/jModule/exec/ConsoleClient.java index a1b111e..f2439f3 100644 --- a/src/main/java/com/jModule/exec/ConsoleClient.java +++ b/src/main/java/com/jModule/exec/ConsoleClient.java @@ -17,7 +17,7 @@ * windows terminals. * * @author Pierce Kelaita - * @version 1.0.3 + * @version 1.1.0 * */ public class ConsoleClient { @@ -43,7 +43,8 @@ public ConsoleClient(String appname, Module homeModule) { } /** - * Sets whether the client will log history of user commands. + * Sets whether the client will log history of user commands. This value is set + * to false by default. * * @param enable * if true, client will log command history @@ -166,10 +167,23 @@ private Module runModule(Module m) throws InterruptedException, IOException { } } + /** + * Adds a possible module to the client. The user can switch to this module by + * typing its name in the CLI + * + * @param m + * Module to add + */ public void addModule(Module m) { modules.add(m); } + /** + * Removes a possible module from the client. + * + * @param m + * Module to remove + */ public void removeModule(Module m) { modules.remove(m); } diff --git a/src/main/java/com/jModule/util/InputUtil.java b/src/main/java/com/jModule/util/InputUtil.java index 6f0de41..dd1e99d 100644 --- a/src/main/java/com/jModule/util/InputUtil.java +++ b/src/main/java/com/jModule/util/InputUtil.java @@ -8,7 +8,7 @@ * currently untested on Windows terminals. * * @author Pierce Kelaita - * @version 1.0.3 + * @version 1.1.0 * */ public class InputUtil {