fix hsscript history

This commit is contained in:
Peter Hormanns 2017-06-29 12:02:02 +02:00
parent 203d896066
commit bb42be700e
2 changed files with 12 additions and 4 deletions

View File

@ -8,7 +8,7 @@
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>hsadmin-cli</artifactId>
<version>1.0.3</version>
<version>1.0.4</version>
<packaging>jar</packaging>
<name>HSAdmin-Cli</name>
@ -37,12 +37,12 @@
<dependency>
<groupId>jline</groupId>
<artifactId>jline</artifactId>
<version>2.14.2</version>
<version>2.14.5</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.3.1</version>
<version>1.4</version>
</dependency>
</dependencies>
<build>

View File

@ -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
}
}
}