-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtext.go
135 lines (124 loc) · 5.13 KB
/
text.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// Package text contains the text (and eventually translations) for the usql
// application.
package text
import (
"regexp"
"strings"
)
// Various usql text bits.
var (
CommandName = `usql`
CommandVersion = `0.0.0-dev`
PassfileName = CommandName + `pass`
Banner = `the universal command-line interface for SQL databases`
NotConnected = `(not connected)`
HelpPrefix = `help`
QuitPrefix = `quit`
ExitPrefix = `exit`
WelcomeDesc = `Type "` + HelpPrefix + `" for help.`
QueryBufferEmpty = `Query buffer is empty.`
QueryBufferReset = `Query buffer reset (cleared).`
InvalidCommand = `Invalid command \%s. Try \? for help.`
ExtraArgumentIgnored = `\%s: extra argument %q ignored`
MissingRequiredArg = `\%s: missing required argument`
Copyright = CommandName + ", " + Banner + ".\n\n" + License
RowCount = `(%d rows)`
AvailableDrivers = `Available Drivers:`
ConnInfo = `Connected with driver %s (%s)`
EnterPassword = `Enter password: `
EnterPreviousPassword = `Enter previous password: `
PasswordsDoNotMatch = `Passwords do not match, trying again ...`
NewPassword = `Enter new password: `
ConfirmPassword = `Confirm password: `
PasswordChangeFailed = `\password for %q failed: %v`
CouldNotSetVariable = `could not set variable %q`
// PasswordChangeSucceeded = `\password succeeded for %q`
HelpDesc string
HelpDescShort = `Use \? for help or press control-C to clear the input buffer.`
HelpBanner = `You are using ` + CommandName + ", " + Banner + `.`
HelpCommandPrefix = `Type: `
HelpCommands = [][]string{
{`copyright`, `for distribution terms`},
//{`h`, `for help with SQL commands`},
{`?`, `for help with ` + CommandName + ` commands`},
{`g`, `or terminate with semicolon to execute query`},
{`q`, `to quit`},
}
QuitDesc = `Use \q to quit.`
UnknownFormatFieldName = `unknown option: %s`
FormatFieldInvalid = `unrecognized value %q for "%s"`
FormatFieldInvalidValue = `unrecognized value %q for "%s": %s expected`
FormatFieldNameSetMap = map[string]string{
`border`: `Border style is %d.`,
`columns`: `Target width is %d.`,
`expanded`: `Expanded display is %s.`,
`expanded_auto`: `Expanded display is used automatically.`,
`fieldsep`: `Field separator is %q.`,
`fieldsep_zero`: `Field separator is zero byte.`,
`footer`: `Default footer is %s.`,
`format`: `Output format is %s.`,
`linestyle`: `Line style is %s.`,
`locale`: `Locale is %q.`,
`null`: `Null display is %q.`,
`numericlocale`: `Locale-adjusted numeric output is %s.`,
`pager`: `Pager usage is %s.`,
`pager_min_lines`: `Pager won't be used for less than %d line(s).`,
`recordsep`: `Field separator is %q.`,
`recordsep_zero`: `Record separator is zero byte.`,
`tableattr`: `Table attributes are %q.`,
`time`: `Time display is %s.`,
`title`: `Title is %q.`,
`tuples_only`: `Tuples only is %s.`,
`unicode_border_linestyle`: `Unicode border line style is %q.`,
`unicode_column_linestyle`: `Unicode column line style is %q.`,
`unicode_header_linestyle`: `Unicode header line style is %q.`,
}
FormatFieldNameUnsetMap = map[string]string{
`tableattr`: `Table attributes unset.`,
`title`: `Title is unset.`,
}
TimingSet = `Timing is %s.`
TimingDesc = `Time: %0.3f ms`
InvalidValue = `invalid -%s value %q: %s`
NotSupportedByDriver = `%s not supported by %s driver`
RelationNotFound = `Did not find any relation named "%s".`
InvalidOption = `invalid option %q`
NotificationReceived = `Asynchronous notification %q %sreceived from server process with PID %d.`
NotificationPayload = `with payload %q `
UnknownShortAlias = `(unk)`
)
func init() {
// setup help description
cmds := make([]string, len(HelpCommands))
for i, h := range HelpCommands {
cmds[i] = `\` + h[0] + " " + h[1]
}
HelpDesc = HelpBanner +
"\n" + HelpCommandPrefix +
strings.Join(cmds, "\n"+strings.Repeat(" ", len(HelpCommandPrefix)))
}
var spaceRE = regexp.MustCompile(`\s+`)
// Command returns the command name without spaces.
var Command = func() string {
return spaceRE.ReplaceAllString(CommandName, "")
}
// CommandLower returns the lower case command name without spaces.
var CommandLower = func() string {
return strings.ToLower(Command())
}
// CommandUpper returns the upper case command name without spaces.
var CommandUpper = func() string {
return strings.ToUpper(Command())
}
// UsageTemplate returns the usage template.
var UsageTemplate = func() string {
n := CommandLower()
return n + `, ` + Banner + `
Usage:
` + n + ` [OPTIONS]... [DSN]
Arguments:
DSN database url
{{if .Context.Flags}}\
Options:
{{.Context.Flags|FlagsToTwoColumns|FormatTwoColumns}}{{end}}`
}