From 0b4f4174050b4e2ef111200dfdb8dc0247e36a51 Mon Sep 17 00:00:00 2001
From: Robert Goldmann <deadlocker@gmx.de>
Date: Sun, 8 Oct 2017 12:34:48 +0200
Subject: [PATCH] #200 - added command "delte client log"

---
 .../{commands => }/CommandBundle.java         | 17 ++++++--
 .../ui/commandLine/CommandLine.java           |  2 -
 .../ui/commandLine/CommandLineController.java |  2 -
 .../{commands => }/HistoryEntry.java          |  2 +-
 .../ui/commandLine/HistoryType.java           |  6 +++
 .../ui/commandLine/commands/Command.java      |  8 ++--
 .../ui/commandLine/commands/CommandClear.java |  4 +-
 .../commandLine/commands/CommandDelete.java   | 41 +++++++++++++++++++
 .../ui/commandLine/commands/CommandHelp.java  | 10 +++--
 .../ui/commandLine/commands/CommandList.java  |  4 +-
 .../ui/commandLine/commands/CommandOpen.java  |  7 ++--
 .../commands/CommandShortcuts.java            |  4 +-
 .../ui/commandLine/commands/HistoryType.java  |  6 ---
 .../commands/PossibleCommands.java            |  3 +-
 .../ui/controller/Controller.java             |  2 +-
 .../ui/commandLine/_en.properties             | 10 ++++-
 16 files changed, 96 insertions(+), 32 deletions(-)
 rename BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/{commands => }/CommandBundle.java (63%)
 rename BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/{commands => }/HistoryEntry.java (84%)
 create mode 100644 BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/HistoryType.java
 create mode 100644 BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandDelete.java
 delete mode 100644 BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/HistoryType.java

diff --git a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandBundle.java b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/CommandBundle.java
similarity index 63%
rename from BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandBundle.java
rename to BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/CommandBundle.java
index 6a4f0966b..5600b99d5 100644
--- a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandBundle.java
+++ b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/CommandBundle.java
@@ -1,9 +1,8 @@
-package de.deadlocker8.budgetmasterclient.ui.commandLine.commands;
+package de.deadlocker8.budgetmasterclient.ui.commandLine;
 
+import java.text.MessageFormat;
 import java.util.ResourceBundle;
 
-import de.deadlocker8.budgetmasterclient.ui.commandLine.CommandLineController;
-
 public class CommandBundle
 {
 	private CommandLineController controller;
@@ -22,7 +21,17 @@ public class CommandBundle
 	public ResourceBundle getLanguageBundle()
 	{
 		return languageBundle;
-	}	
+	}
+	
+	public String getString(String key)
+	{
+		return languageBundle.getString(key);
+	}
+	
+	public String getString(String key, Object... args)
+	{
+		return MessageFormat.format(languageBundle.getString(key), args);
+	}
 
 	public void setController(CommandLineController controller)
 	{
diff --git a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/CommandLine.java b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/CommandLine.java
index 0e642519d..eba15f5f9 100644
--- a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/CommandLine.java
+++ b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/CommandLine.java
@@ -4,8 +4,6 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.ResourceBundle;
 
-import de.deadlocker8.budgetmasterclient.ui.commandLine.commands.CommandBundle;
-import de.deadlocker8.budgetmasterclient.ui.commandLine.commands.HistoryEntry;
 import javafx.fxml.FXMLLoader;
 import javafx.scene.Parent;
 import javafx.scene.Scene;
diff --git a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/CommandLineController.java b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/CommandLineController.java
index e3f15027e..c84fec6b9 100644
--- a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/CommandLineController.java
+++ b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/CommandLineController.java
@@ -4,8 +4,6 @@ import java.util.ArrayList;
 import java.util.Comparator;
 
 import de.deadlocker8.budgetmasterclient.ui.commandLine.commands.Command;
-import de.deadlocker8.budgetmasterclient.ui.commandLine.commands.HistoryEntry;
-import de.deadlocker8.budgetmasterclient.ui.commandLine.commands.HistoryType;
 import de.deadlocker8.budgetmasterclient.ui.commandLine.commands.PossibleCommands;
 import javafx.application.Platform;
 import javafx.event.EventHandler;
diff --git a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/HistoryEntry.java b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/HistoryEntry.java
similarity index 84%
rename from BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/HistoryEntry.java
rename to BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/HistoryEntry.java
index ff972e700..3454e2876 100644
--- a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/HistoryEntry.java
+++ b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/HistoryEntry.java
@@ -1,4 +1,4 @@
-package de.deadlocker8.budgetmasterclient.ui.commandLine.commands;
+package de.deadlocker8.budgetmasterclient.ui.commandLine;
 
 public class HistoryEntry
 {
diff --git a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/HistoryType.java b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/HistoryType.java
new file mode 100644
index 000000000..3b6f3c878
--- /dev/null
+++ b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/HistoryType.java
@@ -0,0 +1,6 @@
+package de.deadlocker8.budgetmasterclient.ui.commandLine;
+
+public enum HistoryType
+{
+	COMMAND, MESSAGE
+}
\ No newline at end of file
diff --git a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/Command.java b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/Command.java
index 1e3ddc4fe..c2ad67b0c 100644
--- a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/Command.java
+++ b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/Command.java
@@ -1,5 +1,7 @@
 package de.deadlocker8.budgetmasterclient.ui.commandLine.commands;
 
+import de.deadlocker8.budgetmasterclient.ui.commandLine.CommandBundle;
+
 public abstract class Command
 {
 	public String keyword;
@@ -23,13 +25,13 @@ public abstract class Command
 	
 	public boolean isValid(String[] command)
 	{
-		if((command.length - 1) < numberOfParams || (command.length -1) > numberOfParams)
+		if((command.length - 1) == numberOfParams)
 		{
-			return false;
+			return true;
 		}
 		else
 		{
-			return true;
+			return false;
 		}
 	}
 	
diff --git a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandClear.java b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandClear.java
index 69f59bbd6..f9aa8f8aa 100644
--- a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandClear.java
+++ b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandClear.java
@@ -1,5 +1,7 @@
 package de.deadlocker8.budgetmasterclient.ui.commandLine.commands;
 
+import de.deadlocker8.budgetmasterclient.ui.commandLine.CommandBundle;
+
 /**
  * Clears the history log and console
  */
@@ -17,7 +19,7 @@ public class CommandClear extends Command
 	{		
 		if(!isValid(command))
 		{			
-			bundle.getController().print(bundle.getLanguageBundle().getString("error.invalid.arguments"));
+			bundle.getController().print(bundle.getString("error.invalid.arguments"));
 			return;
 		}	
 		
diff --git a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandDelete.java b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandDelete.java
new file mode 100644
index 000000000..c160bb382
--- /dev/null
+++ b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandDelete.java
@@ -0,0 +1,41 @@
+package de.deadlocker8.budgetmasterclient.ui.commandLine.commands;
+
+import de.deadlocker8.budgetmasterclient.ui.commandLine.CommandBundle;
+import logger.Logger;
+
+public class CommandDelete extends Command
+{
+	public CommandDelete()
+	{		
+		super.keyword = "delete";		
+		super.numberOfParams = 1;
+		super.helptText = "help.delete";
+	}
+
+	@Override
+	public void execute(String[] command, CommandBundle bundle)
+	{		
+		if(!isValid(command))
+		{			
+			bundle.getController().print(bundle.getString("error.invalid.arguments"));
+			return;
+		}
+		
+		if(command[1].equals("log-client"))
+		{
+			Logger.clearLogFile();
+			bundle.getController().print(bundle.getString("delete.success", "log-client", Logger.getFolder()));
+			return;
+		}
+		
+		if(command[1].equals("log-server"))
+		{
+			//TODO
+//			Logger.clearLogFile();
+//			bundle.getController().print(bundle.getString("delete.success", "log-server", Logger.getFolder()));
+			return;
+		}
+			
+		bundle.getController().print(bundle.getString("error.invalid.parameter", command[1], keyword));
+	}
+}
\ No newline at end of file
diff --git a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandHelp.java b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandHelp.java
index 0358b33d3..88680e5ed 100644
--- a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandHelp.java
+++ b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandHelp.java
@@ -2,6 +2,8 @@ package de.deadlocker8.budgetmasterclient.ui.commandLine.commands;
 
 import java.util.MissingResourceException;
 
+import de.deadlocker8.budgetmasterclient.ui.commandLine.CommandBundle;
+
 /**
  * prints help for given command
  */
@@ -20,7 +22,7 @@ public class CommandHelp extends Command
 	{		
 		if(!isValid(command))
 		{			
-			bundle.getController().print(bundle.getLanguageBundle().getString("error.invalid.arguments"));
+			bundle.getController().print(bundle.getString("error.invalid.arguments"));
 			return;
 		}			
 		
@@ -30,16 +32,16 @@ public class CommandHelp extends Command
 			{	
 				try
 				{
-					bundle.getController().print(bundle.getLanguageBundle().getString("help." + command[1]));
+					bundle.getController().print(bundle.getString("help." + command[1]));
 				}
 				catch(MissingResourceException e)
 				{
-					bundle.getController().print(bundle.getLanguageBundle().getString("error.general"));
+					bundle.getController().print(bundle.getString("error.general"));
 				}
 				return;
 			}
 		}		
 				
-		bundle.getController().print(bundle.getLanguageBundle().getString("error.no.help"));		
+		bundle.getController().print(bundle.getString("error.no.help"));		
 	}
 }
diff --git a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandList.java b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandList.java
index 92ba1054a..6ea40040c 100644
--- a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandList.java
+++ b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandList.java
@@ -3,6 +3,8 @@ package de.deadlocker8.budgetmasterclient.ui.commandLine.commands;
 import java.util.ArrayList;
 import java.util.Comparator;
 
+import de.deadlocker8.budgetmasterclient.ui.commandLine.CommandBundle;
+
 /**
  * Lists all available commands
  */
@@ -21,7 +23,7 @@ public class CommandList extends Command
 	{		
 		if(!isValid(command))
 		{			
-			bundle.getController().print(bundle.getLanguageBundle().getString("error.invalid.arguments"));
+			bundle.getController().print(bundle.getString("error.invalid.arguments"));
 			return;
 		}
 		
diff --git a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandOpen.java b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandOpen.java
index d2e74e4e5..bf4ef69b8 100644
--- a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandOpen.java
+++ b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandOpen.java
@@ -6,6 +6,7 @@ import java.io.IOException;
 import java.nio.file.Paths;
 
 import de.deadlocker8.budgetmaster.logic.utils.Strings;
+import de.deadlocker8.budgetmasterclient.ui.commandLine.CommandBundle;
 import tools.Localization;
 import tools.PathUtils;
 
@@ -23,13 +24,13 @@ public class CommandOpen extends Command
 	{		
 		if(!isValid(command))
 		{			
-			bundle.getController().print(bundle.getLanguageBundle().getString("error.invalid.arguments"));
+			bundle.getController().print(bundle.getString("error.invalid.arguments"));
 			return;
 		}
 		
 		if(!command[1].equals("settings"))
 		{			
-			bundle.getController().print(bundle.getLanguageBundle().getString("error.invalid.arguments"));
+			bundle.getController().print(bundle.getString("error.invalid.parameter", command[1], keyword));
 			return;
 		}
 		
@@ -37,7 +38,7 @@ public class CommandOpen extends Command
 		{	
 			File folder = Paths.get(PathUtils.getOSindependentPath() + Localization.getString(Strings.FOLDER)).toFile();
 			Desktop.getDesktop().open(folder);
-			bundle.getController().print(bundle.getLanguageBundle().getString("help.success") + " " +  folder.getAbsolutePath());
+			bundle.getController().print(bundle.getString("open.success", folder.getAbsolutePath()));
 		}
 		catch(IOException e)
 		{
diff --git a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandShortcuts.java b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandShortcuts.java
index e442ac216..bb99c3e1e 100644
--- a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandShortcuts.java
+++ b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandShortcuts.java
@@ -1,5 +1,7 @@
 package de.deadlocker8.budgetmasterclient.ui.commandLine.commands;
 
+import de.deadlocker8.budgetmasterclient.ui.commandLine.CommandBundle;
+
 /**
  * Lists all available Shortcuts
  */
@@ -16,6 +18,6 @@ public class CommandShortcuts extends Command
 	public void execute(String[] command, CommandBundle bundle)
 	{		
 		bundle.getController().print("Available Shortcuts:");
-		bundle.getController().print(bundle.getLanguageBundle().getString("info.shortcuts"));
+		bundle.getController().print(bundle.getString("info.shortcuts"));
 	}
 }
\ No newline at end of file
diff --git a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/HistoryType.java b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/HistoryType.java
deleted file mode 100644
index fe72a3bd1..000000000
--- a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/HistoryType.java
+++ /dev/null
@@ -1,6 +0,0 @@
-package de.deadlocker8.budgetmasterclient.ui.commandLine.commands;
-
-public enum HistoryType
-{
-	COMMAND, MESSAGE
-}
\ No newline at end of file
diff --git a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/PossibleCommands.java b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/PossibleCommands.java
index 88aff006d..907982b05 100644
--- a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/PossibleCommands.java
+++ b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/PossibleCommands.java
@@ -10,6 +10,7 @@ public class PossibleCommands
 				new CommandHelp(),
 				new CommandClear(),
 				new CommandShortcuts(),
-				new CommandOpen()
+				new CommandOpen(),
+				new CommandDelete()
 			));	
 }
\ No newline at end of file
diff --git a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/controller/Controller.java b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/controller/Controller.java
index bcedcde8f..d21c15085 100644
--- a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/controller/Controller.java
+++ b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/controller/Controller.java
@@ -26,8 +26,8 @@ import de.deadlocker8.budgetmaster.logic.updater.VersionInformation;
 import de.deadlocker8.budgetmaster.logic.utils.Colors;
 import de.deadlocker8.budgetmaster.logic.utils.Helpers;
 import de.deadlocker8.budgetmaster.logic.utils.Strings;
+import de.deadlocker8.budgetmasterclient.ui.commandLine.CommandBundle;
 import de.deadlocker8.budgetmasterclient.ui.commandLine.CommandLine;
-import de.deadlocker8.budgetmasterclient.ui.commandLine.commands.CommandBundle;
 import de.deadlocker8.budgetmasterclient.utils.UIHelpers;
 import fontAwesome.FontIconType;
 import javafx.animation.FadeTransition;
diff --git a/BudgetMasterClient/src/main/resources/de/deadlocker8/budgetmaster/ui/commandLine/_en.properties b/BudgetMasterClient/src/main/resources/de/deadlocker8/budgetmaster/ui/commandLine/_en.properties
index b58ee7894..c88d1ad9a 100644
--- a/BudgetMasterClient/src/main/resources/de/deadlocker8/budgetmaster/ui/commandLine/_en.properties
+++ b/BudgetMasterClient/src/main/resources/de/deadlocker8/budgetmaster/ui/commandLine/_en.properties
@@ -2,13 +2,19 @@ help.list=list - lists all possible commands
 help.help=help - shows help for given command\nSYNTAX:  help [COMMAND]
 help.clear=clear - clears the history
 help.shortcuts=shortcuts - lists all available shortcuts
-help.open=open - opens files and folders\nSYNTAX: open [FILE]\npossible Files: settings
 
 error.general=An error occurred.
 error.unknown.command=Unknown command. Use \"list\" for a list of possible commands.
 error.invalid.arguments=Invalid arguments. Use \"help commandname\" for help.
+error.invalid.parameter=Invalid parameter {0}.\nUse \"help {1}\" for a detailed list.
 error.no.help=Unknown command as parameter. Can't display help. Use \"list\" for a list of possible commands.
 
 info.shortcuts=[ENTER] - execute command\n[UP] - scroll through recently used commands\n[ESC] - clear input\n[TAB] - autocomplete
 
-help.success=Successfully opened folder
\ No newline at end of file
+# open
+help.open=open - opens files and folders\nSYNTAX: open [PARAMETER]\npossible parameters: settings
+open.success=Successfully opened folder {0}
+
+# delete
+help.delete=delte - deletes files\nSYNTAX: delete [PARAMETER]\npossible parameters:\nlog-client\nlog-server
+delete.success=Successfully deleted {0} (in folder: {1})
-- 
GitLab