Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/pkg/cli/sql.go b/pkg/cli/sql.go
- index 5957fae4bb..c7b399de99 100644
- --- a/pkg/cli/sql.go
- +++ b/pkg/cli/sql.go
- @@ -53,7 +53,7 @@ const (
- `
- )
- -const defaultPromptPattern = "%n@%M/%?%x>"
- +const defaultPromptPattern = "%n@%M/%/%x>"
- // sqlShellCmd opens a sql shell.
- var sqlShellCmd = &cobra.Command{
- @@ -243,8 +243,7 @@ var options = map[string]struct {
- set func(c *cliState, val string) error
- reset func(c *cliState) error
- // display is used to retrieve the current value.
- - display func(c *cliState) string
- - nextState cliStateEnum
- + display func(c *cliState) string
- }{
- `display_format`: {
- "the output format for tabular data (pretty, csv, tsv, html, sql, records, raw)",
- @@ -262,7 +261,6 @@ var options = map[string]struct {
- return nil
- },
- func(_ *cliState) string { return cliCtx.tableDisplayFormat.String() },
- - 0,
- },
- `echo`: {
- "show SQL queries before they are sent to the server",
- @@ -271,7 +269,6 @@ var options = map[string]struct {
- func(_ *cliState, _ string) error { sqlCtx.echo = true; return nil },
- func(_ *cliState) error { sqlCtx.echo = false; return nil },
- func(_ *cliState) string { return strconv.FormatBool(sqlCtx.echo) },
- - 0,
- },
- `errexit`: {
- "exit the shell upon a query error",
- @@ -280,7 +277,6 @@ var options = map[string]struct {
- func(c *cliState, _ string) error { c.errExit = true; return nil },
- func(c *cliState) error { c.errExit = false; return nil },
- func(c *cliState) string { return strconv.FormatBool(c.errExit) },
- - 0,
- },
- `check_syntax`: {
- "check the SQL syntax before running a query (needs SHOW SYNTAX support on the server)",
- @@ -289,7 +285,6 @@ var options = map[string]struct {
- func(c *cliState, _ string) error { c.checkSyntax = true; return nil },
- func(c *cliState) error { c.checkSyntax = false; return nil },
- func(c *cliState) string { return strconv.FormatBool(c.checkSyntax) },
- - 0,
- },
- `show_times`: {
- "display the execution time after each query",
- @@ -298,10 +293,9 @@ var options = map[string]struct {
- func(_ *cliState, _ string) error { cliCtx.showTimes = true; return nil },
- func(_ *cliState) error { cliCtx.showTimes = false; return nil },
- func(_ *cliState) string { return strconv.FormatBool(cliCtx.showTimes) },
- - 0,
- },
- `prompt1`: {
- - "prompt string to use before each command (the following are expanded: %M full host, %m host, %> port number, %n user, %? database, %x txn status)",
- + "prompt string to use before each command (the following are expanded: %M full host, %m host, %> port number, %n user, %/ database, %x txn status)",
- false,
- true,
- func(c *cliState, val string) error {
- @@ -313,7 +307,6 @@ var options = map[string]struct {
- return nil
- },
- func(c *cliState) string { return c.customPromptPattern },
- - cliRefreshPrompts,
- },
- }
- @@ -389,10 +382,6 @@ func (c *cliState) handleSet(args []string, nextState, errState cliStateEnum) cl
- return errState
- }
- - if opt.nextState != 0 {
- - return opt.nextState
- - }
- -
- return nextState
- }
- @@ -412,9 +401,6 @@ func (c *cliState) handleUnset(args []string, nextState, errState cliStateEnum)
- fmt.Fprintf(stderr, "\\unset %s: %v\n", args[0], err)
- return errState
- }
- - if opt.nextState != 0 {
- - return opt.nextState
- - }
- return nextState
- }
- @@ -535,7 +521,7 @@ func (c *cliState) pipeSyscmd(line string, nextState, errState cliStateEnum) cli
- }
- // rePromptFmt: available keys compile with regex expression one time.
- -var rePromptFmt = regexp.MustCompile("%(.)")
- +var rePromptFmt = regexp.MustCompile("%.")
- // doRefreshPrompts refreshes the prompts of the client depending on the
- // status of the current transaction.
- @@ -567,23 +553,25 @@ func (c *cliState) doRefreshPrompts(nextState cliStateEnum) cliStateEnum {
- userName = parsedURL.User.Username()
- }
- return userName
- - case "%?":
- + case "%/":
- dbName, hasDbName := c.refreshDatabaseName() // database name.
- - if hasDbName {
- - return dbName
- + if !hasDbName {
- + return "?"
- }
- + return dbName
- case "%x": // txn status.
- c.refreshTransactionStatus()
- return c.lastKnownTxnStatus
- case "%%":
- return "%"
- - // default:
- - // err = fmt.Errorf("unrecognized format code in prompt: %q", m)
- - // return err.Error()
- + default:
- + err = fmt.Errorf("unrecognized format code in prompt: %q", m)
- + return ""
- }
- -
- - return m
- })
- + if err != nil {
- + c.fullPrompt = err.Error()
- + }
- c.fullPrompt += " "
Add Comment
Please, Sign In to add comment