Skip to content

Commit

Permalink
[SQLLINE-332] Added historyFlags property to customize !history outpu…
Browse files Browse the repository at this point in the history
…t, updated docs
  • Loading branch information
snuyanzin committed Aug 24, 2019
1 parent 32a915c commit c47c709
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 5 deletions.
12 changes: 12 additions & 0 deletions src/docbkx/manual.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1453,6 +1453,12 @@ sqlline> !help
!go Select the current connection
!help Print a summary of command usage
!history Display the command history
-d Print timestamps for each event (default for !history)
-f Print full time date stamps in the US format
-E Print full time date stamps in the European format
-i Print full time date stamps in ISO8601 format
-n Suppresses command numbers
-r Reverses the order of the commands
!importedkeys List all the imported keys for the specified table
!indexes List all the indexes for the specified table
!isolation Set the transaction isolation for this connection
Expand Down Expand Up @@ -1533,6 +1539,12 @@ sqlline>
<refname>history</refname>
<refpurpose>
Display the command history
-d Print timestamps for each event (default for !history)
-f Print full time date stamps in the US format
-E Print full time date stamps in the European format
-i Print full time date stamps in ISO8601 format
-n Suppresses command numbers
-r Reverses the order of the commands
</refpurpose>
</refnamediv>

Expand Down
1 change: 1 addition & 0 deletions src/main/java/sqlline/BuiltInProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public enum BuiltInProperty implements SqlLineProperty {
HEADER_INTERVAL("headerInterval", Type.INTEGER, 100),
HISTORY_FILE("historyFile", Type.STRING,
new File(SqlLineOpts.saveDir(), "history").getAbsolutePath()),
HISTORY_FLAGS("historyFlags", Type.STRING, "-d"),
INCREMENTAL("incremental", Type.BOOLEAN, false),
INCREMENTAL_BUFFER_ROWS("incrementalBufferRows", Type.INTEGER, 1000),
ISOLATION("isolation", Type.STRING, "TRANSACTION_REPEATABLE_READ",
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/sqlline/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public void history(String line, DispatchCallback callback) {
sqlLine.getOutputStream(),
sqlLine.getErrorStream(),
argsLine.isEmpty()
? new String[]{"-d"}
? new String[]{sqlLine.getOpts().getHistoryFlags()}
: sqlLine.split(argsLine, " "));
} catch (Exception e) {
callback.setToFailure();
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/sqlline/SqlLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -1471,7 +1471,18 @@ String wrap(String toWrap, int len, int start) {
tok.hasMoreTokens();) {
String next = tok.nextToken();
final int x = line.length();
line.append(line.length() == 0 ? "" : " ").append(next);
final int index = next.indexOf('\n');
if (index >= 0) {
line.setLength(x + index);
buff.append(line).append(' ').append(next, 0, index)
.append(SEPARATOR).append(head);
line.setLength(0);
if (next.length() > index + 1) {
line.append(next.substring(index + 1));
}
} else {
line.append(line.length() == 0 ? "" : " ").append(next);
}
if (line.length() > len) {
// The line is now too long. Backtrack: remove the last word, start a
// new line containing just that word.
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/sqlline/SqlLineCommandCompleter.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ class SqlLineCommandCompleter extends AggregateCompleter {
} else {
final String commandName = SqlLine.COMMAND_PREFIX + cmd;
final String helpText = commandHandler.getHelpText();
final int firstEndOfLineIndex = helpText.indexOf('\n');
compl.add(new StringsCompleter(
new SqlLineCandidate(
sqlLine, AttributedString.stripAnsi(commandName),
commandName, sqlLine.loc("command-name"), helpText,
commandName, sqlLine.loc("command-name"),
firstEndOfLineIndex == -1
? helpText : helpText.substring(0, firstEndOfLineIndex),
// there could be whatever else instead helpText
// which is the same for commands with all theirs aliases
null, helpText, true)));
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/sqlline/SqlLineOpts.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import sqlline.SqlLineProperty.Type;

import static sqlline.BuiltInProperty.AUTO_COMMIT;
import static sqlline.BuiltInProperty.HISTORY_FLAGS;
import static sqlline.BuiltInProperty.READ_ONLY;
import static sqlline.BuiltInProperty.AUTO_SAVE;
import static sqlline.BuiltInProperty.COLOR;
Expand Down Expand Up @@ -923,6 +924,10 @@ public Pattern getCompiledConfirmPattern() {
}
return compiledConfirmPattern;
}

public String getHistoryFlags() {
return get(HISTORY_FLAGS);
}
}

// End SqlLineOpts.java
10 changes: 9 additions & 1 deletion src/main/resources/sqlline/SqlLine.properties
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ variables:\
\nhistoryFile path File in which to save command history. Default is\
\n $HOME/.sqlline/history (UNIX, Linux, Mac OS),\
\n $HOME/sqlline/history (Windows)\
\nhistoryFlags String Default flags for !history command\
\nincremental true/false Do not receive all rows from server before\
\n printing the first row; uses fewer resources,\
\n especially for long-running queries, but column\
Expand Down Expand Up @@ -188,7 +189,13 @@ help-alias: Create a new command alias
help-unalias: Unset a command alias
help-scan: Scan for installed JDBC drivers
help-sql: Execute a SQL command
help-history: Display the command history
help-history: Display the command history\n\
-d Print timestamps for each event (default for !history) \n\
-f Print full time date stamps in the US format \n\
-E Print full time date stamps in the European format \n\
-i Print full time date stamps in ISO8601 format \n\
-n Suppresses command numbers \n\
-r Reverses the order of the commands
help-record: Record all output to the specified file
help-indexes: List all the indexes for the specified table
help-primarykeys: List all the primary keys for the specified table
Expand Down Expand Up @@ -325,6 +332,7 @@ cmd-usage: Usage: java sqlline.SqlLine \n \
\ --maxColumnWidth=MAXCOLWIDTH the maximum width to use when displaying columns\n \
\ --maxHistoryFileRows=ROWS the maximum number of history rows to store in history file\n \
\ --maxHistoryRows=ROWS the maximum number of history rows to store in memory\n \
\ --historyFlags=FLAGS default flags for !history command\n \
\ --mode=[emacs/vi] the editing mode\n \
\ --silent=[true/false] be more silent\n \
\ --autosave=[true/false] automatically save preferences\n \
Expand Down
31 changes: 30 additions & 1 deletion src/main/resources/sqlline/manual.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ help
help — Display help information
history
history — Display the command history
-d Print timestamps for each event (default for !history)
-f Print full time date stamps in the US format
-E Print full time date stamps in the European format
-i Print full time date stamps in ISO8601 format
-n Suppresses command numbers
-r Reverses the order of the commands
importedkeys
importedkeys — List imported foreign keys for a database
indexes
Expand Down Expand Up @@ -193,6 +199,12 @@ help
help — Display help information
history
history — Display the command history
-d Print timestamps for each event (default for !history)
-f Print full time date stamps in the US format
-E Print full time date stamps in the European format
-i Print full time date stamps in ISO8601 format
-n Suppresses command numbers
-r Reverses the order of the commands
importedkeys
importedkeys — List imported foreign keys for a database
indexes
Expand Down Expand Up @@ -422,6 +434,12 @@ help
help — Display help information
history
history — Display the command history
-d Print timestamps for each event (default for !history)
-f Print full time date stamps in the US format
-E Print full time date stamps in the European format
-i Print full time date stamps in ISO8601 format
-n Suppresses command numbers
-r Reverses the order of the commands
importedkeys
importedkeys — List imported foreign keys for a database
indexes
Expand Down Expand Up @@ -1088,6 +1106,12 @@ sqlline> !help
!go Select the current connection
!help Print a summary of command usage
!history Display the command history
-d Print timestamps for each event (default for !history)
-f Print full time date stamps in the US format
-E Print full time date stamps in the European format
-i Print full time date stamps in ISO8601 format
-n Suppresses command numbers
-r Reverses the order of the commands
!importedkeys List all the imported keys for the specified table
!indexes List all the indexes for the specified table
!isolation Set the transaction isolation for this connection
Expand Down Expand Up @@ -1224,7 +1248,12 @@ history
Name

history — Display the command history

-d Print timestamps for each event (default for !history)
-f Print full time date stamps in the US format
-E Print full time date stamps in the European format
-i Print full time date stamps in ISO8601 format
-n Suppresses command numbers
-r Reverses the order of the commands
Synopsis

!history
Expand Down

0 comments on commit c47c709

Please sign in to comment.