forked from xo/usql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetacmd.go
91 lines (87 loc) · 2.58 KB
/
metacmd.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
// Package metacmd contains meta information and implentation for usql's
// backslash (\) commands.
package metacmd
import (
"github.com/xo/usql/stmt"
"github.com/xo/usql/text"
)
// Metacmd represents a command and associated meta information about it.
type Metacmd uint
// Decode converts a command name (or alias) into a Runner.
func Decode(name string, params *stmt.Params) (Runner, error) {
mc, ok := cmdMap[name]
if !ok || name == "" {
return nil, text.ErrUnknownCommand
}
cmd := cmds[mc]
return RunnerFunc(func(h Handler) (Option, error) {
p := &Params{
Handler: h,
Name: name,
Params: params,
}
err := cmd.Process(p)
return p.Option, err
}), nil
}
// Command types.
const (
// None is an empty command.
None Metacmd = iota
// Question is question meta command (\?)
Question
// Quit is the quit meta command (\?).
Quit
// Copyright is the copyright meta command (\copyright).
Copyright
// Connect is the connect meta command (\c, \connect).
Connect
// Copy is the copy meta command (\copy).
Copy
// Disconnect is the disconnect meta command (\Z).
Disconnect
// Password is the change password meta command (\password).
Password
// ConnectionInfo is the connection info meta command (\conninfo).
ConnectionInfo
// Drivers is the driver info meta command (\drivers).
Drivers
// Describe is the describe meta command (\d and variants).
Describe
// Exec is the execute meta command (\g and variants).
Exec
// Edit is the edit query buffer meta command (\e).
Edit
// Print is the print query buffer meta command (\p, \print, \raw).
Print
// Reset is the reset query buffer meta command (\r, \reset).
Reset
// Echo is the echo meta command (\echo, \warn, \qecho).
Echo
// Write is the write meta command (\w).
Write
// ChangeDir is the system change directory meta command (\cd).
ChangeDir
// SetEnv is the system set environment variable meta command (\setenv).
SetEnv
// Shell is the system shell exec meta command (\!).
Shell
// Out is the switch output meta command (\o).
Out
// Include is the system include file meta command (\i and variants).
Include
// Transact is the transaction meta command (\begin, \commit, \rollback).
Transact
// Prompt is the variable prompt meta command (\prompt).
Prompt
// SetVar is the set variable meta command (\set).
SetVar
// Unset is the variable unset meta command (\unset).
Unset
// SetFormatVar is the set format variable meta commands (\pset, \a, \C, \f, \H, \t, \T, \x).
SetFormatVar
// Timing is the timing meta command (\timing).
Timing
// Stats is the show stats meta command (\ss and variants).
Stats
)