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

View File

@ -13,6 +13,7 @@ import jline.console.history.FileHistory;
public class ConsoleWrapper implements PasswordReader { public class ConsoleWrapper implements PasswordReader {
private ConsoleReader cons; private ConsoleReader cons;
private FileHistory history;
private String prompt; private String prompt;
public void open(final String prompt) throws JSCliException { public void open(final String prompt) throws JSCliException {
@ -22,7 +23,8 @@ public class ConsoleWrapper implements PasswordReader {
cons.setExpandEvents(false); cons.setExpandEvents(false);
cons.setPrompt(prompt); cons.setPrompt(prompt);
final String userHome = System.getProperty("user.home"); 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) { } catch (IOException e) {
throw new JSCliException(e); throw new JSCliException(e);
} }
@ -37,6 +39,12 @@ public class ConsoleWrapper implements PasswordReader {
return line; return line;
} catch (IOException e) { } catch (IOException e) {
throw new JSCliException(e); throw new JSCliException(e);
} finally {
try {
history.flush();
} catch (IOException e) {
// dont care about
}
} }
} }