diff --git a/pkg/cli/interactive_tests/test_local_cmds.tcl b/pkg/cli/interactive_tests/test_local_cmds.tcl index 3707454ccc36..8982afebfea9 100755 --- a/pkg/cli/interactive_tests/test_local_cmds.tcl +++ b/pkg/cli/interactive_tests/test_local_cmds.tcl @@ -105,7 +105,30 @@ eexpect "display_format\ttsv" eexpect root@ end_test +start_test "Check that \\x toggles display format" +send "\\x\r\\set\r" +eexpect "Option*|*display_format" +eexpect "Value*|*records" +eexpect root@ + +send "\\x\r\\set\r" +eexpect "display_format*|*table" +eexpect root@ +end_test + +start_test "Check that \\x with on or off enables/disables records display format" +send "\\x on\r\\set\r" +eexpect "Option*|*display_format" +eexpect "Value*|*records" +eexpect root@ + +send "\\x off\r\\set\r" +eexpect "display_format*|*table" +eexpect root@ +end_test + start_test "Check various ways to set a boolean flag." +send "\\set display_format=tsv\r" send "\\set show_times=false\r\\set\r" eexpect "show_times\tfalse" eexpect root@ diff --git a/pkg/cli/sql.go b/pkg/cli/sql.go index 4d31694c703a..bebc3b0abfe7 100644 --- a/pkg/cli/sql.go +++ b/pkg/cli/sql.go @@ -79,6 +79,9 @@ Informational \du list the users for all databases. \d [TABLE] show details about columns in the specified table, or alias for '\dt' if no table is specified. +Formatting + \x [on|off] toggle records display format. + Operating System \! CMD run an external command and print its results on standard output. @@ -1161,6 +1164,28 @@ func (c *cliState) doHandleCliCmd(loopState, nextState cliStateEnum) cliStateEnu } return c.invalidSyntax(errState, `%s. Try \? for help`, c.lastInputLine) + case `\x`: + format := tableDisplayRecords + switch len(cmd) { + case 1: + if cliCtx.tableDisplayFormat == tableDisplayRecords { + format = tableDisplayTable + } + case 2: + b, err := parseBool(cmd[1]) + if err != nil { + return c.invalidSyntax(errState, `%s. Try \? for help.`, c.lastInputLine) + } else if b { + format = tableDisplayRecords + } else { + format = tableDisplayTable + } + default: + return c.invalidSyntax(errState, `%s. Try \? for help.`, c.lastInputLine) + } + cliCtx.tableDisplayFormat = format + return loopState + case `\demo`: return c.handleDemo(cmd[1:], loopState, errState)