Guest User

Untitled

a guest
Jul 17th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.40 KB | None | 0 0
  1. diff --git a/pkg/cli/sql.go b/pkg/cli/sql.go
  2. index 5957fae4bb..c7b399de99 100644
  3. --- a/pkg/cli/sql.go
  4. +++ b/pkg/cli/sql.go
  5. @@ -53,7 +53,7 @@ const (
  6. `
  7. )
  8.  
  9. -const defaultPromptPattern = "%n@%M/%?%x>"
  10. +const defaultPromptPattern = "%n@%M/%/%x>"
  11.  
  12. // sqlShellCmd opens a sql shell.
  13. var sqlShellCmd = &cobra.Command{
  14. @@ -243,8 +243,7 @@ var options = map[string]struct {
  15. set func(c *cliState, val string) error
  16. reset func(c *cliState) error
  17. // display is used to retrieve the current value.
  18. - display func(c *cliState) string
  19. - nextState cliStateEnum
  20. + display func(c *cliState) string
  21. }{
  22. `display_format`: {
  23. "the output format for tabular data (pretty, csv, tsv, html, sql, records, raw)",
  24. @@ -262,7 +261,6 @@ var options = map[string]struct {
  25. return nil
  26. },
  27. func(_ *cliState) string { return cliCtx.tableDisplayFormat.String() },
  28. - 0,
  29. },
  30. `echo`: {
  31. "show SQL queries before they are sent to the server",
  32. @@ -271,7 +269,6 @@ var options = map[string]struct {
  33. func(_ *cliState, _ string) error { sqlCtx.echo = true; return nil },
  34. func(_ *cliState) error { sqlCtx.echo = false; return nil },
  35. func(_ *cliState) string { return strconv.FormatBool(sqlCtx.echo) },
  36. - 0,
  37. },
  38. `errexit`: {
  39. "exit the shell upon a query error",
  40. @@ -280,7 +277,6 @@ var options = map[string]struct {
  41. func(c *cliState, _ string) error { c.errExit = true; return nil },
  42. func(c *cliState) error { c.errExit = false; return nil },
  43. func(c *cliState) string { return strconv.FormatBool(c.errExit) },
  44. - 0,
  45. },
  46. `check_syntax`: {
  47. "check the SQL syntax before running a query (needs SHOW SYNTAX support on the server)",
  48. @@ -289,7 +285,6 @@ var options = map[string]struct {
  49. func(c *cliState, _ string) error { c.checkSyntax = true; return nil },
  50. func(c *cliState) error { c.checkSyntax = false; return nil },
  51. func(c *cliState) string { return strconv.FormatBool(c.checkSyntax) },
  52. - 0,
  53. },
  54. `show_times`: {
  55. "display the execution time after each query",
  56. @@ -298,10 +293,9 @@ var options = map[string]struct {
  57. func(_ *cliState, _ string) error { cliCtx.showTimes = true; return nil },
  58. func(_ *cliState) error { cliCtx.showTimes = false; return nil },
  59. func(_ *cliState) string { return strconv.FormatBool(cliCtx.showTimes) },
  60. - 0,
  61. },
  62. `prompt1`: {
  63. - "prompt string to use before each command (the following are expanded: %M full host, %m host, %> port number, %n user, %? database, %x txn status)",
  64. + "prompt string to use before each command (the following are expanded: %M full host, %m host, %> port number, %n user, %/ database, %x txn status)",
  65. false,
  66. true,
  67. func(c *cliState, val string) error {
  68. @@ -313,7 +307,6 @@ var options = map[string]struct {
  69. return nil
  70. },
  71. func(c *cliState) string { return c.customPromptPattern },
  72. - cliRefreshPrompts,
  73. },
  74. }
  75.  
  76. @@ -389,10 +382,6 @@ func (c *cliState) handleSet(args []string, nextState, errState cliStateEnum) cl
  77. return errState
  78. }
  79.  
  80. - if opt.nextState != 0 {
  81. - return opt.nextState
  82. - }
  83. -
  84. return nextState
  85. }
  86.  
  87. @@ -412,9 +401,6 @@ func (c *cliState) handleUnset(args []string, nextState, errState cliStateEnum)
  88. fmt.Fprintf(stderr, "\\unset %s: %v\n", args[0], err)
  89. return errState
  90. }
  91. - if opt.nextState != 0 {
  92. - return opt.nextState
  93. - }
  94. return nextState
  95. }
  96.  
  97. @@ -535,7 +521,7 @@ func (c *cliState) pipeSyscmd(line string, nextState, errState cliStateEnum) cli
  98. }
  99.  
  100. // rePromptFmt: available keys compile with regex expression one time.
  101. -var rePromptFmt = regexp.MustCompile("%(.)")
  102. +var rePromptFmt = regexp.MustCompile("%.")
  103.  
  104. // doRefreshPrompts refreshes the prompts of the client depending on the
  105. // status of the current transaction.
  106. @@ -567,23 +553,25 @@ func (c *cliState) doRefreshPrompts(nextState cliStateEnum) cliStateEnum {
  107. userName = parsedURL.User.Username()
  108. }
  109. return userName
  110. - case "%?":
  111. + case "%/":
  112. dbName, hasDbName := c.refreshDatabaseName() // database name.
  113. - if hasDbName {
  114. - return dbName
  115. + if !hasDbName {
  116. + return "?"
  117. }
  118. + return dbName
  119. case "%x": // txn status.
  120. c.refreshTransactionStatus()
  121. return c.lastKnownTxnStatus
  122. case "%%":
  123. return "%"
  124. - // default:
  125. - // err = fmt.Errorf("unrecognized format code in prompt: %q", m)
  126. - // return err.Error()
  127. + default:
  128. + err = fmt.Errorf("unrecognized format code in prompt: %q", m)
  129. + return ""
  130. }
  131. -
  132. - return m
  133. })
  134. + if err != nil {
  135. + c.fullPrompt = err.Error()
  136. + }
  137.  
  138. c.fullPrompt += " "
Add Comment
Please, Sign In to add comment