Skip to content

Commit 913b982

Browse files
committed
Cleaning up ON_ERROR_STOP / QUIET parsing logic
Fixes some superficial errors and simplifies/cleans up ON_ERROR_STOP / QUIET environment variable parsing.
1 parent c8a4edf commit 913b982

File tree

6 files changed

+63
-74
lines changed

6 files changed

+63
-74
lines changed

env/env.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ func OpenFile(u *user.User, path string, relative bool) (string, *os.File, error
7777
func EditFile(u *user.User, path, line, s string) ([]rune, error) {
7878
ed := All()["EDITOR"]
7979
if ed == "" {
80-
return nil, text.ErrNoEditorDefined
80+
if p, err := exec.LookPath("vi"); err == nil {
81+
ed = p
82+
} else {
83+
return nil, text.ErrNoEditorDefined
84+
}
8185
}
8286
if path != "" {
8387
path = passfile.Expand(u.HomeDir, path)

env/types.go

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,6 @@ func (v Vars) All() map[string]string {
3636

3737
var vars, pvars Vars
3838

39-
// a map of functions to optionally parse parameters when being set
40-
// Takes: value, name string
41-
// Returns: parsedValue string, error
42-
// See ParseBool for an example
43-
var variableParseFunctions = map[string]func(string, string) (string, error){
44-
"ON_ERROR_STOP": ParseBoolEmptyIsOn,
45-
"QUIET": ParseBoolEmptyIsOn,
46-
}
47-
4839
func init() {
4940
// get USQL_* variables
5041
enableHostInformation := "true"
@@ -135,19 +126,19 @@ func ValidIdentifier(n string) error {
135126
}
136127

137128
// Set sets a variable.
138-
// Values are optionally parsed by a helper function if one is defined in
139-
// variableParseFunctions
140129
func Set(name, value string) error {
141130
if err := ValidIdentifier(name); err != nil {
142131
return err
143132
}
144-
// parse and validate value if there's a function defined in variableParseFunctions
145-
if parseFunction, ok := variableParseFunctions[name]; ok {
146-
parsedValue, err := parseFunction(value, name)
147-
if err != nil {
148-
return fmt.Errorf(text.FormatFieldInvalid, value, name)
133+
if name == "ON_ERROR_STOP" || name == "QUIET" {
134+
if value == "" {
135+
value = "on"
136+
} else {
137+
var err error
138+
if value, err = ParseBool(value, name); err != nil {
139+
return err
140+
}
149141
}
150-
value = parsedValue
151142
}
152143
vars.Set(name, value)
153144
return nil
@@ -220,14 +211,6 @@ func ParseBool(value, name string) (string, error) {
220211
return "", fmt.Errorf(text.FormatFieldInvalidValue, value, name, "Boolean")
221212
}
222213

223-
// ParseBoolEmptyIsOn works like ParseBool but treats empty values as "on"
224-
func ParseBoolEmptyIsOn(value, name string) (string, error) {
225-
if value == "" {
226-
return "on", nil
227-
}
228-
return ParseBool(value, name)
229-
}
230-
231214
func ParseKeywordBool(value, name string, keywords ...string) (string, error) {
232215
v := strings.ToLower(value)
233216
switch v {
@@ -324,7 +307,7 @@ func Pset(name, value string) (string, error) {
324307
case "pager":
325308
s, err := ParseKeywordBool(value, name, "always")
326309
if err != nil {
327-
return "", text.ErrInvalidFormatExpandedType
310+
return "", text.ErrInvalidFormatPagerType
328311
}
329312
pvars[name] = s
330313
case "expanded":

go.mod

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ require (
2222
github.com/genjidb/genji v0.15.1
2323
github.com/go-sql-driver/mysql v1.6.0
2424
github.com/gocql/gocql v1.2.1
25-
github.com/godror/godror v0.34.0
25+
github.com/godror/godror v0.35.0
2626
github.com/gohxs/readline v0.0.0-20171011095936-a780388e6e7c
2727
github.com/google/go-cmp v0.5.9
2828
github.com/google/goexpect v0.0.0-20210430020637-ab937bf7fd6f
@@ -62,7 +62,7 @@ require (
6262
)
6363

6464
require (
65-
cloud.google.com/go v0.105.0 // indirect
65+
cloud.google.com/go v0.106.0 // indirect
6666
cloud.google.com/go/bigquery v1.43.0 // indirect
6767
cloud.google.com/go/compute v1.12.1 // indirect
6868
cloud.google.com/go/compute/metadata v0.2.1 // indirect
@@ -86,19 +86,19 @@ require (
8686
github.com/andybalholm/brotli v1.0.4 // indirect
8787
github.com/apache/arrow/go/arrow v0.0.0-20211112161151-bc219186db40 // indirect
8888
github.com/apache/thrift v0.17.0 // indirect
89-
github.com/aws/aws-sdk-go v1.44.133 // indirect
89+
github.com/aws/aws-sdk-go v1.44.135 // indirect
9090
github.com/aws/aws-sdk-go-v2 v1.17.1 // indirect
9191
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.9 // indirect
92-
github.com/aws/aws-sdk-go-v2/credentials v1.12.23 // indirect
93-
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.37 // indirect
92+
github.com/aws/aws-sdk-go-v2/credentials v1.12.24 // indirect
93+
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.38 // indirect
9494
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.25 // indirect
9595
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.19 // indirect
9696
github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.16 // indirect
9797
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.10 // indirect
9898
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.20 // indirect
9999
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.19 // indirect
100100
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.13.19 // indirect
101-
github.com/aws/aws-sdk-go-v2/service/s3 v1.29.1 // indirect
101+
github.com/aws/aws-sdk-go-v2/service/s3 v1.29.2 // indirect
102102
github.com/aws/smithy-go v1.13.4 // indirect
103103
github.com/beltran/gohive v1.5.3 // indirect
104104
github.com/beltran/gosasl v0.0.0-20220904020400-625f43db35e0 // indirect
@@ -116,7 +116,7 @@ require (
116116
github.com/cncf/xds/go v0.0.0-20220520190051-1e77728a1eaa // indirect
117117
github.com/cockroachdb/errors v1.9.0 // indirect
118118
github.com/cockroachdb/logtags v0.0.0-20211118104740-dabe8e521a4f // indirect
119-
github.com/cockroachdb/pebble v0.0.0-20221108223155-9aeeed0a1037 // indirect
119+
github.com/cockroachdb/pebble v0.0.0-20221110182746-b7e1586503e2 // indirect
120120
github.com/cockroachdb/redact v1.1.3 // indirect
121121
github.com/containerd/cgroups v1.0.4 // indirect
122122
github.com/containerd/containerd v1.6.7 // indirect
@@ -138,7 +138,7 @@ require (
138138
github.com/exasol/error-reporting-go v0.1.1 // indirect
139139
github.com/form3tech-oss/jwt-go v3.2.5+incompatible // indirect
140140
github.com/gabriel-vasile/mimetype v1.4.1 // indirect
141-
github.com/getsentry/sentry-go v0.14.0 // indirect
141+
github.com/getsentry/sentry-go v0.15.0 // indirect
142142
github.com/go-faster/city v1.0.1 // indirect
143143
github.com/go-faster/errors v0.6.1 // indirect
144144
github.com/go-logfmt/logfmt v0.5.1 // indirect
@@ -224,20 +224,20 @@ require (
224224
go.uber.org/atomic v1.10.0 // indirect
225225
go.uber.org/multierr v1.8.0 // indirect
226226
go.uber.org/zap v1.23.0 // indirect
227-
golang.org/x/crypto v0.1.0 // indirect
228-
golang.org/x/exp v0.0.0-20221108223516-5d533826c662 // indirect
229-
golang.org/x/mod v0.6.0 // indirect
227+
golang.org/x/crypto v0.2.0 // indirect
228+
golang.org/x/exp v0.0.0-20221110155412-d0897a79cd37 // indirect
229+
golang.org/x/mod v0.7.0 // indirect
230230
golang.org/x/net v0.2.0 // indirect
231-
golang.org/x/oauth2 v0.1.0 // indirect
231+
golang.org/x/oauth2 v0.2.0 // indirect
232232
golang.org/x/sync v0.1.0 // indirect
233233
golang.org/x/sys v0.2.0 // indirect
234234
golang.org/x/term v0.2.0 // indirect
235235
golang.org/x/text v0.4.0 // indirect
236-
golang.org/x/tools v0.2.0 // indirect
236+
golang.org/x/tools v0.3.0 // indirect
237237
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
238238
google.golang.org/api v0.103.0 // indirect
239239
google.golang.org/appengine v1.6.7 // indirect
240-
google.golang.org/genproto v0.0.0-20221107162902-2d387536bcdd // indirect
240+
google.golang.org/genproto v0.0.0-20221109142239-94d6d90a7d66 // indirect
241241
google.golang.org/grpc v1.50.1 // indirect
242242
google.golang.org/protobuf v1.28.1 // indirect
243243
gopkg.in/inf.v0 v0.9.1 // indirect

0 commit comments

Comments
 (0)