@@ -24,8 +24,7 @@ import (
24
24
// Cmd is a command implementation.
25
25
type Cmd struct {
26
26
Section Section
27
- Desc Desc
28
- Aliases []Desc
27
+ Descs []Desc
29
28
Process func (* Params ) error
30
29
}
31
30
@@ -42,8 +41,8 @@ func init() {
42
41
cmds = []Cmd {
43
42
Question : {
44
43
Section : SectionHelp ,
45
- Desc : Desc { "?" , "[commands]" , "show help on backslash commands" },
46
- Aliases : [] Desc {
44
+ Descs : [] Desc {
45
+ { "?" , "[commands]" , "show help on backslash commands" },
47
46
{"?" , "options" , "show help on " + text .CommandName + " command-line options" },
48
47
{"?" , "variables" , "show help on special " + text .CommandName + " variables" },
49
48
},
@@ -80,16 +79,20 @@ func init() {
80
79
},
81
80
Quit : {
82
81
Section : SectionGeneral ,
83
- Desc : Desc {"q" , "" , "quit " + text .CommandName },
84
- Aliases : []Desc {{"quit" , "" , "" }},
82
+ Descs : []Desc {
83
+ {"q" , "" , "quit " + text .CommandName },
84
+ {"quit" , "" , "" },
85
+ },
85
86
Process : func (p * Params ) error {
86
87
p .Option .Quit = true
87
88
return nil
88
89
},
89
90
},
90
91
Copyright : {
91
92
Section : SectionGeneral ,
92
- Desc : Desc {"copyright" , "" , "show " + text .CommandName + " usage and distribution terms" },
93
+ Descs : []Desc {
94
+ {"copyright" , "" , "show " + text .CommandName + " usage and distribution terms" },
95
+ },
93
96
Process : func (p * Params ) error {
94
97
stdout := p .Handler .IO ().Stdout ()
95
98
if typ := env .TermGraphics (); typ .Available () {
@@ -101,7 +104,9 @@ func init() {
101
104
},
102
105
ConnectionInfo : {
103
106
Section : SectionConnection ,
104
- Desc : Desc {"conninfo" , "" , "display information about the current database connection" },
107
+ Descs : []Desc {
108
+ {"conninfo" , "" , "display information about the current database connection" },
109
+ },
105
110
Process : func (p * Params ) error {
106
111
s := text .NotConnected
107
112
if db , u := p .Handler .DB (), p .Handler .URL (); db != nil && u != nil {
@@ -113,7 +118,9 @@ func init() {
113
118
},
114
119
Drivers : {
115
120
Section : SectionGeneral ,
116
- Desc : Desc {"drivers" , "" , "display information about available database drivers" },
121
+ Descs : []Desc {
122
+ {"drivers" , "" , "display information about available database drivers" },
123
+ },
117
124
Process : func (p * Params ) error {
118
125
stdout , stderr := p .Handler .IO ().Stdout (), p .Handler .IO ().Stderr ()
119
126
var cmd * exec.Cmd
@@ -158,8 +165,8 @@ func init() {
158
165
},
159
166
Connect : {
160
167
Section : SectionConnection ,
161
- Desc : Desc {"c" , "DSN" , "connect to database url" },
162
- Aliases : [] Desc {
168
+ Descs : [] Desc {
169
+ { "c" , "DSN" , "connect to database url" },
163
170
{"c" , "DRIVER PARAMS..." , "connect to database with driver and parameters" },
164
171
{"connect" , "" , "" },
165
172
},
@@ -175,8 +182,8 @@ func init() {
175
182
},
176
183
SetConnVar : {
177
184
Section : SectionConnection ,
178
- Desc : Desc { "cset" , "[NAME [DSN]]" , "set named connection, or list all if no parameters" },
179
- Aliases : [] Desc {
185
+ Descs : [] Desc {
186
+ { "cset" , "[NAME [DSN]]" , "set named connection, or list all if no parameters" },
180
187
{"cset" , "NAME DRIVER PARAMS..." , "define named connection for database driver" },
181
188
},
182
189
Process : func (p * Params ) error {
@@ -203,16 +210,20 @@ func init() {
203
210
},
204
211
Disconnect : {
205
212
Section : SectionConnection ,
206
- Desc : Desc {"Z" , "" , "close database connection" },
207
- Aliases : []Desc {{"disconnect" , "" , "" }},
213
+ Descs : []Desc {
214
+ {"Z" , "" , "close database connection" },
215
+ {"disconnect" , "" , "" },
216
+ },
208
217
Process : func (p * Params ) error {
209
218
return p .Handler .Close ()
210
219
},
211
220
},
212
221
Password : {
213
222
Section : SectionConnection ,
214
- Desc : Desc {"password" , "[USERNAME]" , "change the password for a user" },
215
- Aliases : []Desc {{"passwd" , "" , "" }},
223
+ Descs : []Desc {
224
+ {"password" , "[USERNAME]" , "change the password for a user" },
225
+ {"passwd" , "" , "" },
226
+ },
216
227
Process : func (p * Params ) error {
217
228
username , err := p .Get (true )
218
229
if err != nil {
@@ -231,8 +242,8 @@ func init() {
231
242
},
232
243
Exec : {
233
244
Section : SectionQueryExecute ,
234
- Desc : Desc { "g" , "[(OPTIONS)] [FILE] or ;" , "execute query (and send results to file or |pipe)" },
235
- Aliases : [] Desc {
245
+ Descs : [] Desc {
246
+ { "g" , "[(OPTIONS)] [FILE] or ;" , "execute query (and send results to file or |pipe)" },
236
247
{"G" , "[(OPTIONS)] [FILE]" , "as \\ g, but forces vertical output mode" },
237
248
{"gx" , "[(OPTIONS)] [FILE]" , "as \\ g, but forces expanded output mode" },
238
249
{"gexec" , "" , "execute query and execute each value of the result" },
@@ -309,7 +320,9 @@ func init() {
309
320
},
310
321
Bind : {
311
322
Section : SectionQueryExecute ,
312
- Desc : Desc {"bind" , "[PARAM]..." , "set query parameters" },
323
+ Descs : []Desc {
324
+ {"bind" , "[PARAM]..." , "set query parameters" },
325
+ },
313
326
Process : func (p * Params ) error {
314
327
bind , err := p .GetAll (true )
315
328
if err != nil {
@@ -328,8 +341,10 @@ func init() {
328
341
},
329
342
Edit : {
330
343
Section : SectionQueryBuffer ,
331
- Desc : Desc {"e" , "[FILE] [LINE]" , "edit the query buffer (or file) with external editor" },
332
- Aliases : []Desc {{"edit" , "" , "" }},
344
+ Descs : []Desc {
345
+ {"e" , "[FILE] [LINE]" , "edit the query buffer (or file) with external editor" },
346
+ {"edit" , "" , "" },
347
+ },
333
348
Process : func (p * Params ) error {
334
349
// get last statement
335
350
s , buf := p .Handler .Last (), p .Handler .Buf ()
@@ -357,8 +372,8 @@ func init() {
357
372
},
358
373
Print : {
359
374
Section : SectionQueryBuffer ,
360
- Desc : Desc {"p" , "" , "show the contents of the query buffer" },
361
- Aliases : [] Desc {
375
+ Descs : [] Desc {
376
+ { "p" , "" , "show the contents of the query buffer" },
362
377
{"print" , "" , "" },
363
378
{"raw" , "" , "show the raw (non-interpolated) contents of the query buffer" },
364
379
},
@@ -393,8 +408,10 @@ func init() {
393
408
},
394
409
Reset : {
395
410
Section : SectionQueryBuffer ,
396
- Desc : Desc {"r" , "" , "reset (clear) the query buffer" },
397
- Aliases : []Desc {{"reset" , "" , "" }},
411
+ Descs : []Desc {
412
+ {"r" , "" , "reset (clear) the query buffer" },
413
+ {"reset" , "" , "" },
414
+ },
398
415
Process : func (p * Params ) error {
399
416
p .Handler .Reset (nil )
400
417
p .Handler .Print (text .QueryBufferReset )
@@ -403,8 +420,8 @@ func init() {
403
420
},
404
421
Echo : {
405
422
Section : SectionInputOutput ,
406
- Desc : Desc { "echo" , "[-n] [STRING]" , "write string to standard output (-n for no newline)" },
407
- Aliases : [] Desc {
423
+ Descs : [] Desc {
424
+ { "echo" , "[-n] [STRING]" , "write string to standard output (-n for no newline)" },
408
425
{"qecho" , "[-n] [STRING]" , "write string to \\ o output stream (-n for no newline)" },
409
426
{"warn" , "[-n] [STRING]" , "write string to standard error (-n for no newline)" },
410
427
},
@@ -440,8 +457,10 @@ func init() {
440
457
},
441
458
Write : {
442
459
Section : SectionQueryBuffer ,
443
- Desc : Desc {"w" , "FILE" , "write query buffer to file" },
444
- Aliases : []Desc {{"write" , "" , "" }},
460
+ Descs : []Desc {
461
+ {"w" , "FILE" , "write query buffer to file" },
462
+ {"write" , "" , "" },
463
+ },
445
464
Process : func (p * Params ) error {
446
465
// get last statement
447
466
s , buf := p .Handler .Last (), p .Handler .Buf ()
@@ -457,7 +476,9 @@ func init() {
457
476
},
458
477
ChangeDir : {
459
478
Section : SectionOperatingSystem ,
460
- Desc : Desc {"cd" , "[DIR]" , "change the current working directory" },
479
+ Descs : []Desc {
480
+ {"cd" , "[DIR]" , "change the current working directory" },
481
+ },
461
482
Process : func (p * Params ) error {
462
483
dir , err := p .Get (true )
463
484
if err != nil {
@@ -468,7 +489,9 @@ func init() {
468
489
},
469
490
GetEnv : {
470
491
Section : SectionOperatingSystem ,
471
- Desc : Desc {"getenv" , "VARNAME ENVVAR" , "fetch environment variable" },
492
+ Descs : []Desc {
493
+ {"getenv" , "VARNAME ENVVAR" , "fetch environment variable" },
494
+ },
472
495
Process : func (p * Params ) error {
473
496
n , err := p .Get (true )
474
497
switch {
@@ -490,7 +513,9 @@ func init() {
490
513
},
491
514
SetEnv : {
492
515
Section : SectionOperatingSystem ,
493
- Desc : Desc {"setenv" , "NAME [VALUE]" , "set or unset environment variable" },
516
+ Descs : []Desc {
517
+ {"setenv" , "NAME [VALUE]" , "set or unset environment variable" },
518
+ },
494
519
Process : func (p * Params ) error {
495
520
n , err := p .Get (true )
496
521
if err != nil {
@@ -505,7 +530,9 @@ func init() {
505
530
},
506
531
Timing : {
507
532
Section : SectionOperatingSystem ,
508
- Desc : Desc {"timing" , "[on|off]" , "toggle timing of commands" },
533
+ Descs : []Desc {
534
+ {"timing" , "[on|off]" , "toggle timing of commands" },
535
+ },
509
536
Process : func (p * Params ) error {
510
537
v , err := p .Get (true )
511
538
if err != nil {
@@ -536,15 +563,19 @@ func init() {
536
563
},
537
564
Shell : {
538
565
Section : SectionOperatingSystem ,
539
- Desc : Desc {"!" , "[COMMAND]" , "execute command in shell or start interactive shell" },
566
+ Descs : []Desc {
567
+ {"!" , "[COMMAND]" , "execute command in shell or start interactive shell" },
568
+ },
540
569
Process : func (p * Params ) error {
541
570
return env .Shell (p .GetRaw ())
542
571
},
543
572
},
544
573
Out : {
545
574
Section : SectionInputOutput ,
546
- Desc : Desc {"o" , "[FILE]" , "send all query results to file or |pipe" },
547
- Aliases : []Desc {{"out" , "" , "" }},
575
+ Descs : []Desc {
576
+ {"o" , "[FILE]" , "send all query results to file or |pipe" },
577
+ {"out" , "" , "" },
578
+ },
548
579
Process : func (p * Params ) error {
549
580
p .Handler .SetOutput (nil )
550
581
params , err := p .GetAll (true )
@@ -570,8 +601,8 @@ func init() {
570
601
},
571
602
Include : {
572
603
Section : SectionInputOutput ,
573
- Desc : Desc {"i" , "FILE" , "execute commands from file" },
574
- Aliases : [] Desc {
604
+ Descs : [] Desc {
605
+ { "i" , "FILE" , "execute commands from file" },
575
606
{"ir" , "FILE" , "as \\ i, but relative to location of current script" },
576
607
{"include" , "" , "" },
577
608
{"include_relative" , "" , "" },
@@ -590,8 +621,8 @@ func init() {
590
621
},
591
622
Transact : {
592
623
Section : SectionTransaction ,
593
- Desc : Desc {"begin" , "" , "begin a transaction" },
594
- Aliases : [] Desc {
624
+ Descs : [] Desc {
625
+ { "begin" , "" , "begin a transaction" },
595
626
{"begin" , "[-read-only] [ISOLATION]" , "begin a transaction with isolation level" },
596
627
{"commit" , "" , "commit current transaction" },
597
628
{"rollback" , "" , "rollback (abort) current transaction" },
@@ -650,7 +681,9 @@ func init() {
650
681
},
651
682
Prompt : {
652
683
Section : SectionVariables ,
653
- Desc : Desc {"prompt" , "[-TYPE] VAR [PROMPT]" , "prompt user to set variable" },
684
+ Descs : []Desc {
685
+ {"prompt" , "[-TYPE] VAR [PROMPT]" , "prompt user to set variable" },
686
+ },
654
687
Process : func (p * Params ) error {
655
688
typ := "string"
656
689
ok , n , err := p .GetOptional (true )
@@ -683,7 +716,9 @@ func init() {
683
716
},
684
717
SetVar : {
685
718
Section : SectionVariables ,
686
- Desc : Desc {"set" , "[NAME [VALUE]]" , "set internal variable, or list all if no parameters" },
719
+ Descs : []Desc {
720
+ {"set" , "[NAME [VALUE]]" , "set internal variable, or list all if no parameters" },
721
+ },
687
722
Process : func (p * Params ) error {
688
723
ok , n , err := p .GetOK (true )
689
724
switch {
@@ -708,7 +743,9 @@ func init() {
708
743
},
709
744
Unset : {
710
745
Section : SectionVariables ,
711
- Desc : Desc {"unset" , "NAME" , "unset (delete) internal variable" },
746
+ Descs : []Desc {
747
+ {"unset" , "NAME" , "unset (delete) internal variable" },
748
+ },
712
749
Process : func (p * Params ) error {
713
750
n , err := p .Get (true )
714
751
if err != nil {
@@ -719,8 +756,8 @@ func init() {
719
756
},
720
757
SetPrintVar : {
721
758
Section : SectionFormatting ,
722
- Desc : Desc { "pset" , "[NAME [VALUE]]" , "set table output option" },
723
- Aliases : [] Desc {
759
+ Descs : [] Desc {
760
+ { "pset" , "[NAME [VALUE]]" , "set table output option" },
724
761
{"a" , "" , "toggle between unaligned and aligned output mode" },
725
762
{"C" , "[STRING]" , "set table title, or unset if none" },
726
763
{"f" , "[STRING]" , "show or set field separator for unaligned query output" },
@@ -806,8 +843,8 @@ func init() {
806
843
},
807
844
Describe : {
808
845
Section : SectionInformational ,
809
- Desc : Desc { "d[S+]" , "[NAME]" , "list tables, views, and sequences or describe table, view, sequence, or index" },
810
- Aliases : [] Desc {
846
+ Descs : [] Desc {
847
+ { "d[S+]" , "[NAME]" , "list tables, views, and sequences or describe table, view, sequence, or index" },
811
848
{"da[S+]" , "[PATTERN]" , "list aggregates" },
812
849
{"df[S+]" , "[PATTERN]" , "list functions" },
813
850
{"di[S+]" , "[PATTERN]" , "list indexes" },
@@ -857,7 +894,9 @@ func init() {
857
894
},
858
895
Stats : {
859
896
Section : SectionInformational ,
860
- Desc : Desc {"ss[+]" , "[TABLE|QUERY] [k]" , "show stats for a table or a query" },
897
+ Descs : []Desc {
898
+ {"ss[+]" , "[TABLE|QUERY] [k]" , "show stats for a table or a query" },
899
+ },
861
900
Process : func (p * Params ) error {
862
901
ctx , cancel := signal .NotifyContext (context .Background (), os .Interrupt )
863
902
defer cancel ()
@@ -894,8 +933,8 @@ func init() {
894
933
},
895
934
Copy : {
896
935
Section : SectionInputOutput ,
897
- Desc : Desc {"copy" , "SRC DST QUERY TABLE" , "copy query from source url to table on destination url" },
898
- Aliases : [] Desc {
936
+ Descs : [] Desc {
937
+ { "copy" , "SRC DST QUERY TABLE" , "copy query from source url to table on destination url" },
899
938
{"copy" , "SRC DST QUERY TABLE(A,...)" , "copy query from source url to columns of table on destination url" },
900
939
},
901
940
Process : func (p * Params ) error {
@@ -960,7 +999,7 @@ func init() {
960
999
if mc == None {
961
1000
continue
962
1001
}
963
- name := c .Desc .Name
1002
+ name := c .Descs [ 0 ] .Name
964
1003
if pos := strings .IndexRune (name , '[' ); pos != - 1 {
965
1004
mods := strings .TrimRight (name [pos + 1 :], "]" )
966
1005
name = name [:pos ]
@@ -972,7 +1011,7 @@ func init() {
972
1011
}
973
1012
}
974
1013
cmdMap [name ] = mc
975
- for _ , d := range c .Aliases {
1014
+ for _ , d := range c .Descs {
976
1015
if pos := strings .IndexRune (d .Name , '[' ); pos != - 1 {
977
1016
mods := strings .TrimRight (d .Name [pos + 1 :], "]" )
978
1017
d .Name = d .Name [:pos ]
0 commit comments