Skip to content

Commit

Permalink
updated docs for 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
pkelaita committed Sep 6, 2017
1 parent 3e29392 commit 583d2a9
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 13 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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$ <commands>
```
To see the full list of changes implemented in version 1.1, consult the [Changelog](https://github.com/pkelaita/JModule/blob/master/CHANGELOG.md).
&nbsp;
&nbsp;
## 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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 6 additions & 3 deletions examples/ExampleApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,25 @@ public static void main(String[] args) {
// set up commands

// 'add'
AddCmdLogic addLogic = new AddCmdLogic(); // set up command logic
ArrayList<String> 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<String> 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'
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/jModule/def/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* <P>
* 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
Expand Down
18 changes: 16 additions & 2 deletions src/main/java/com/jModule/exec/ConsoleClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* windows terminals.
*
* @author Pierce Kelaita
* @version 1.0.3
* @version 1.1.0
*
*/
public class ConsoleClient {
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/jModule/util/InputUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* currently untested on Windows terminals.
*
* @author Pierce Kelaita
* @version 1.0.3
* @version 1.1.0
*
*/
public class InputUtil {
Expand Down

0 comments on commit 583d2a9

Please sign in to comment.