From 1069fbd5558ee58f6e603430c4125b3ae137c56a Mon Sep 17 00:00:00 2001 From: Michael Fross Date: Tue, 27 Dec 2022 10:30:31 -0600 Subject: [PATCH] Added the `-L | --license` switch and a new license command - Updated the tests to check that it's working --- pom.xml | 2 +- snap/snapcraft.yaml | 2 +- .../org/fross/rpncalc/CommandLineArgs.java | 11 ++++++- .../java/org/fross/rpncalc/CommandParser.java | 5 ++++ src/main/java/org/fross/rpncalc/Help.java | 29 +++++++++++++++++++ .../fross/rpncalc/CommandLineArgsTest.java | 9 ++++-- 6 files changed, 52 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 368eb49..f44d0a7 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ org.fross rpncalc - 4.6.20 + 4.7.0 jar rpncalc diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index a0d5512..1ffce32 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -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 diff --git a/src/main/java/org/fross/rpncalc/CommandLineArgs.java b/src/main/java/org/fross/rpncalc/CommandLineArgs.java index d105267..17405cc 100644 --- a/src/main/java/org/fross/rpncalc/CommandLineArgs.java +++ b/src/main/java/org/fross/rpncalc/CommandLineArgs.java @@ -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 // --------------------------------------------------------------------------------------------- @@ -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); diff --git a/src/main/java/org/fross/rpncalc/CommandParser.java b/src/main/java/org/fross/rpncalc/CommandParser.java index 10f3ced..551f757 100644 --- a/src/main/java/org/fross/rpncalc/CommandParser.java +++ b/src/main/java/org/fross/rpncalc/CommandParser.java @@ -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": diff --git a/src/main/java/org/fross/rpncalc/Help.java b/src/main/java/org/fross/rpncalc/Help.java index 898587d..b6ae228 100644 --- a/src/main/java/org/fross/rpncalc/Help.java +++ b/src/main/java/org/fross/rpncalc/Help.java @@ -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:"); @@ -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); + } } diff --git a/src/test/java/org/fross/rpncalc/CommandLineArgsTest.java b/src/test/java/org/fross/rpncalc/CommandLineArgsTest.java index 240b09f..acefe27 100644 --- a/src/test/java/org/fross/rpncalc/CommandLineArgsTest.java +++ b/src/test/java/org/fross/rpncalc/CommandLineArgsTest.java @@ -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(); @@ -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); @@ -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(); @@ -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); @@ -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(); @@ -116,6 +118,7 @@ void testMixedCommandLineArgs2() { assertFalse(cli.clNoColor); assertFalse(cli.clVersion); assertTrue(cli.clHelp); + assertTrue(cli.clLicense); assertEquals("MixedLoadFile2.txt", cli.clLoad); } } \ No newline at end of file