Skip to content

Commit

Permalink
Added the -L | --license switch and a new license command
Browse files Browse the repository at this point in the history
- Updated the tests to check that it's working
  • Loading branch information
frossm committed Dec 27, 2022
1 parent eabc225 commit 1069fbd
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.fross</groupId>
<artifactId>rpncalc</artifactId>
<version>4.6.20</version>
<version>4.7.0</version>
<packaging>jar</packaging>

<name>rpncalc</name>
Expand Down
2 changes: 1 addition & 1 deletion snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: rpncalc
version: '4.6.20'
version: '4.7.0'
summary: The command line Reverse Polish Notation (RPN) calculator
description: |
RPNCalc is an easy to use command line based Reverse Polish
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/org/fross/rpncalc/CommandLineArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public class CommandLineArgs {
@Parameter(names = { "-l", "--load" }, description = "Load saved stack file")
protected String clLoad = "";

@Parameter(names = { "-L", "--license" }, description = "Display program usage license")
protected boolean clLicense = false;

// ---------------------------------------------------------------------------------------------
// Process command line parameters with the following methods
// ---------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -87,12 +90,18 @@ public static void ProcessCommandLine(String[] argv) {
Main.calcStack2.setStackNameAndRestore("default", "2");
}

// Version Switch
// Version Display
if (cli.clVersion == true) {
Main.DisplayVersion();
System.exit(0);
}

// License Display
if (cli.clLicense == true) {
Help.DisplayLicense();
System.exit(0);
}

// Disable Colorized Output Switch
if (cli.clNoColor == true) {
Output.enableColor(false);
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/fross/rpncalc/CommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,11 @@ public static void Parse(StackObj calcStack, StackObj calcStack2, String cmdInpu
StackOperations.cmdReverse(calcStack);
break;

// Show License
case "license":
Help.DisplayLicense();
break;

// Version
case "ver":
case "version":
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/org/fross/rpncalc/Help.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public static void Display() {
Output.printColorln(Ansi.Color.WHITE, " -l Load a saved named stack. Create the stack if it does not exist");
Output.printColorln(Ansi.Color.WHITE, " -h | ? Show this help information. Either key will work.");
Output.printColorln(Ansi.Color.WHITE, " -v Display version information as well as latest GitHub release");
Output.printColorln(Ansi.Color.WHITE, " -L Display program usage license. Same as 'license' operational command");
Output.printColorln(Ansi.Color.WHITE, " -z Disable colorized output");

Output.printColorln(Ansi.Color.YELLOW, "\nOperands:");
Expand Down Expand Up @@ -138,9 +139,37 @@ public static void Display() {
Output.printColorln(Ansi.Color.WHITE, " set memslots NUM Set the number of memory slots");
Output.printColorln(Ansi.Color.WHITE, " set width NUM Set the width of the display to num");
Output.printColorln(Ansi.Color.WHITE, " ss Swap primary and secondary stack");
Output.printColorln(Ansi.Color.WHITE, " license Display the software usage license");
Output.printColorln(Ansi.Color.WHITE, " ver Display the current version");
Output.printColorln(Ansi.Color.WHITE, " x|exit Exit Calculator");
Output.printColorln(Ansi.Color.WHITE, " cx|clearexit Clear the stack and then exit");

}

/**
* DisplayLicense(): Simply display the software usage license and return
*
*/
public static void DisplayLicense() {
String licenseText = "MIT License\n\n"

+ "Copyright (c) 2013-" + org.fross.library.Date.getCurrentYear() + " Michael Fross\n\n"

+ "Permission is hereby granted, free of charge, to any person obtaining a copy\n"
+ "of this software and associated documentation files (the \"Software\"), to deal\n"
+ "in the Software without restriction, including without limitation the rights\n"
+ "to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n"
+ "copies of the Software, and to permit persons to whom the Software is\n" + "furnished to do so, subject to the following conditions:\n\n"

+ "The above copyright notice and this permission notice shall be included in all\n" + "copies or substantial portions of the Software.\n\n"

+ "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n"
+ "IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n"
+ "FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n"
+ "AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n"
+ "LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n"
+ "OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n" + "SOFTWARE.\n";

Output.printColorln(Ansi.Color.CYAN, licenseText);
}
}
9 changes: 6 additions & 3 deletions src/test/java/org/fross/rpncalc/CommandLineArgsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class CommandLineArgsTest {
@Test
void testShortCommandLineArgs() {
// Test Short Options
String[] argv1 = { "-D", "-z", "-h", "-v", "-l", "LoadFile.txt" };
String[] argv1 = { "-D", "-z", "-h", "-v", "-L", "-l", "LoadFile.txt" };

CommandLineArgs cli = new CommandLineArgs();
JCommander jc = new JCommander();
Expand All @@ -57,6 +57,7 @@ void testShortCommandLineArgs() {

assertTrue(cli.clDebug);
assertTrue(cli.clNoColor);
assertTrue(cli.clLicense);
assertTrue(cli.clVersion);
assertTrue(cli.clHelp);
assertEquals("LoadFile.txt", cli.clLoad);
Expand All @@ -65,7 +66,7 @@ void testShortCommandLineArgs() {
@Test
void testLongCommandLineArgs() {
// Test Long Options
String[] argv2 = { "--debug", "--no-color", "--help", "--version", "--load", "LongLoadFile.txt" };
String[] argv2 = { "--debug", "--no-color", "--help", "--license", "--version", "--load", "LongLoadFile.txt" };

CommandLineArgs cli = new CommandLineArgs();
JCommander jc = new JCommander();
Expand All @@ -76,6 +77,7 @@ void testLongCommandLineArgs() {

assertTrue(cli.clDebug);
assertTrue(cli.clNoColor);
assertTrue(cli.clLicense);
assertTrue(cli.clVersion);
assertTrue(cli.clHelp);
assertEquals("LongLoadFile.txt", cli.clLoad);
Expand Down Expand Up @@ -103,7 +105,7 @@ void testMixedCommandLineArgs1() {
@Test
void testMixedCommandLineArgs2() {
// Test Mix of Options
String[] argv4 = { "--debug", "-h", "-l", "MixedLoadFile2.txt" };
String[] argv4 = { "--debug", "-h", "--license", "-l", "MixedLoadFile2.txt" };

CommandLineArgs cli = new CommandLineArgs();
JCommander jc = new JCommander();
Expand All @@ -116,6 +118,7 @@ void testMixedCommandLineArgs2() {
assertFalse(cli.clNoColor);
assertFalse(cli.clVersion);
assertTrue(cli.clHelp);
assertTrue(cli.clLicense);
assertEquals("MixedLoadFile2.txt", cli.clLoad);
}
}

0 comments on commit 1069fbd

Please sign in to comment.