@@ -99,7 +99,7 @@ func New(cliargs []string) ContextExecutor {
99
99
return nil
100
100
},
101
101
RunE : func (cmd * cobra.Command , cliargs []string ) error {
102
- // completions
102
+ // completions and short circuits
103
103
switch {
104
104
case bashCompletion :
105
105
return cmd .GenBashCompletionV2 (os .Stdout , ! noDescriptions )
@@ -118,6 +118,7 @@ func New(cliargs []string) ContextExecutor {
118
118
case badHelp :
119
119
return errors .New ("unknown shorthand flag: 'h' in -h" )
120
120
}
121
+ args .Conns = v .GetStringMapString ("connections" )
121
122
// run
122
123
if len (cliargs ) > 0 {
123
124
args .DSN = cliargs [0 ]
@@ -194,15 +195,6 @@ func New(cliargs []string) ContextExecutor {
194
195
_ = flags .BoolP ("help" , "?" , false , "show this help, then exit" )
195
196
_ = c .Flags ().SetAnnotation ("help" , cobra .FlagSetByCobraAnnotation , []string {"true" })
196
197
197
- // expose to metacmd
198
- metacmd .Usage = func (w io.Writer , banner bool ) {
199
- s := c .UsageString ()
200
- if banner {
201
- s = text .Short () + "\n \n " + s
202
- }
203
- _ , _ = w .Write ([]byte (s ))
204
- }
205
-
206
198
// mark hidden
207
199
for _ , name := range []string {
208
200
"no-psqlrc" , "no-usqlrc" , "var" , "variable" ,
@@ -212,6 +204,15 @@ func New(cliargs []string) ContextExecutor {
212
204
} {
213
205
flags .Lookup (name ).Hidden = true
214
206
}
207
+
208
+ // expose to metacmd
209
+ metacmd .Usage = func (w io.Writer , banner bool ) {
210
+ s := c .UsageString ()
211
+ if banner {
212
+ s = text .Short () + "\n \n " + s
213
+ }
214
+ _ , _ = w .Write ([]byte (s ))
215
+ }
215
216
return c
216
217
}
217
218
@@ -227,43 +228,42 @@ func Run(ctx context.Context, args *Args) error {
227
228
if err != nil {
228
229
return err
229
230
}
231
+
230
232
// determine if interactive
231
233
interactive := isatty .IsTerminal (os .Stdout .Fd ()) && isatty .IsTerminal (os .Stdin .Fd ())
232
234
cygwin := isatty .IsCygwinTerminal (os .Stdout .Fd ()) && isatty .IsCygwinTerminal (os .Stdin .Fd ())
233
235
forceNonInteractive := len (args .CommandOrFiles ) != 0
236
+
234
237
// enable term graphics
235
- /*
236
- if !forceNonInteractive && interactive && !cygwin {
237
- // NOTE: this is done here and not in the env.init() package, because
238
- // NOTE: we need to determine if it is interactive first, otherwise it
239
- // NOTE: could mess up the non-interactive output with control characters
240
- var typ string
241
- if s, _ := env.Getenv(commandUpper+"_TERM_GRAPHICS", "TERM_GRAPHICS"); s != "" {
242
- typ = s
243
- }
244
- if err := env.Set("TERM_GRAPHICS", typ); err != nil {
245
- return err
246
- }
238
+ if ! forceNonInteractive && interactive && ! cygwin {
239
+ // NOTE: this is done here and not in the env.init() package, because
240
+ // NOTE: we need to determine if it is interactive first, otherwise it
241
+ // NOTE: could mess up the non-interactive output with control characters
242
+ var typ string
243
+ if s , _ := env .Getenv (text .CommandUpper ()+ "_TERM_GRAPHICS" , "TERM_GRAPHICS" ); s != "" {
244
+ typ = s
247
245
}
248
- */
246
+ if err := env .Set ("TERM_GRAPHICS" , typ ); err != nil {
247
+ return err
248
+ }
249
+ }
249
250
250
- // fmt.Fprintf(os.Stdout, "\n\nVARS : %v\n\ nPVARS: %v\n\n \n", args.Variables, args.PVariables)
251
+ // fmt.Fprintf(os.Stdout, "VARS : %v\nPVARS: %v\n", args.Variables, args.PVariables)
251
252
252
- // handle variables
253
+ // set variables
253
254
for _ , v := range args .Variables {
254
255
if i := strings .Index (v , "=" ); i != - 1 {
255
256
_ = env .Set (v [:i ], v [i + 1 :])
256
257
} else {
257
258
_ = env .Unset (v )
258
259
}
259
260
}
261
+ // set pvariables
260
262
for _ , v := range args .PVariables {
261
263
if i := strings .Index (v , "=" ); i != - 1 {
262
264
vv := v [i + 1 :]
263
265
if c := vv [0 ]; c == '\'' || c == '"' {
264
- var err error
265
- vv , err = env .Dequote (vv , c )
266
- if err != nil {
266
+ if vv , err = env .Dequote (vv , c ); err != nil {
267
267
return err
268
268
}
269
269
}
@@ -283,7 +283,7 @@ func Run(ctx context.Context, args *Args) error {
283
283
}
284
284
defer l .Close ()
285
285
// create handler
286
- h := handler .New (l , u , wd , args .NoPassword )
286
+ h := handler .New (l , u , wd , args .NoPassword , args . Conns )
287
287
// force password
288
288
dsn := args .DSN
289
289
if args .ForcePassword {
@@ -337,6 +337,7 @@ type Args struct {
337
337
SingleTransaction bool
338
338
Variables []string
339
339
PVariables []string
340
+ Conns map [string ]string
340
341
}
341
342
342
343
// CommandOrFile is a special type to deal with interspersed -c, -f,
0 commit comments