-
Notifications
You must be signed in to change notification settings - Fork 338
/
register.go
66 lines (53 loc) · 3.38 KB
/
register.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
/*
Copyright 2021 CodeNotary, Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cli
type command struct {
name string
short string
command func(args []string) (string, error)
args []string
variable bool
}
func (cli *cli) initCommands() {
// Auth
cli.Register(&command{"login", "Login using the specified username and password", cli.login, []string{"username"}, false})
cli.Register(&command{"logout", "", cli.logout, nil, false})
cli.Register(&command{"use", "Select database", cli.UseDatabase, []string{"databasename"}, false})
// Get commands
cli.Register(&command{"safeget", "Get and verify item having the specified key", cli.safeGetKey, []string{"key"}, false})
cli.Register(&command{"get", "Get item having the specified key", cli.getKey, []string{"key"}, false})
cli.Register(&command{"gettx", "Return a tx by id", cli.getTxByID, []string{"id"}, false})
// Set commands
cli.Register(&command{"set", "Add new item having the specified key and value", cli.set, []string{"key", "value"}, false})
cli.Register(&command{"safeset", "Add and verify new item having the specified key and value", cli.safeset, []string{"key", "value"}, false})
cli.Register(&command{"safezadd", "Add and verify new key with score to a new or existing sorted set", cli.safeZAdd, []string{"setname", "score", "key"}, false})
cli.Register(&command{"zadd", "Add new key with score to a new or existing sorted set", cli.zAdd, []string{"setname", "score", "key"}, false})
// Current status commands
cli.Register(&command{"current", "Return the last tx and hash stored locally", cli.currentState, nil, false})
// Reference commands
cli.Register(&command{"reference", "Add new reference to an existing key", cli.reference, []string{"refkey", "key"}, false})
cli.Register(&command{"safereference", "Add and verify new reference to an existing key", cli.safereference, []string{"refkey", "key"}, false})
// Scannner commands
cli.Register(&command{"scan", "Iterate over keys having the specified prefix", cli.scan, []string{"prefix"}, false})
cli.Register(&command{"zscan", "Iterate over a sorted set", cli.zScan, []string{"prefix"}, false})
cli.Register(&command{"count", "Count keys having the specified prefix", cli.count, []string{"prefix"}, false})
// Misc commands
cli.Register(&command{"status", "", cli.healthCheck, nil, false})
cli.Register(&command{"history", "Fetch history for the item having the specified key", cli.history, []string{"key"}, false})
cli.Register(&command{"version", "Print version", cli.version, nil, false})
// SQL
cli.Register(&command{"exec", "Executes sql statement", cli.sqlExec, []string{"statement"}, false})
cli.Register(&command{"query", "Query sql statement", cli.sqlQuery, []string{"statement"}, false})
cli.Register(&command{"describe", "Describe table", cli.describeTable, []string{"table"}, false})
cli.Register(&command{"tables", "List tables", cli.listTables, nil, false})
}