From bb42be700e4ca27fcc6430ad579f0631f3cef54f Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Thu, 29 Jun 2017 12:02:02 +0200 Subject: [PATCH] fix hsscript history --- cli/pom.xml | 6 +++--- .../java/de/hsadmin/jscli/console/ConsoleWrapper.java | 10 +++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/cli/pom.xml b/cli/pom.xml index 90a38bb..3d0d887 100644 --- a/cli/pom.xml +++ b/cli/pom.xml @@ -8,7 +8,7 @@ 1.0-SNAPSHOT hsadmin-cli - 1.0.3 + 1.0.4 jar HSAdmin-Cli @@ -37,12 +37,12 @@ jline jline - 2.14.2 + 2.14.5 commons-cli commons-cli - 1.3.1 + 1.4 diff --git a/cli/src/main/java/de/hsadmin/jscli/console/ConsoleWrapper.java b/cli/src/main/java/de/hsadmin/jscli/console/ConsoleWrapper.java index 478af11..25dad42 100644 --- a/cli/src/main/java/de/hsadmin/jscli/console/ConsoleWrapper.java +++ b/cli/src/main/java/de/hsadmin/jscli/console/ConsoleWrapper.java @@ -13,6 +13,7 @@ import jline.console.history.FileHistory; public class ConsoleWrapper implements PasswordReader { private ConsoleReader cons; + private FileHistory history; private String prompt; public void open(final String prompt) throws JSCliException { @@ -22,7 +23,8 @@ public class ConsoleWrapper implements PasswordReader { cons.setExpandEvents(false); cons.setPrompt(prompt); final String userHome = System.getProperty("user.home"); - cons.setHistory(new FileHistory(new File(userHome + "/.hsscript_history"))); + history = new FileHistory(new File(userHome + "/.hsscript_history")); + cons.setHistory(history); } catch (IOException e) { throw new JSCliException(e); } @@ -37,6 +39,12 @@ public class ConsoleWrapper implements PasswordReader { return line; } catch (IOException e) { throw new JSCliException(e); + } finally { + try { + history.flush(); + } catch (IOException e) { + // dont care about + } } }