cli

package
Version: v0.0.0-...-ad86efc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2016 License: Apache-2.0 Imports: 76 Imported by: 0

Documentation

Overview

Example (Basic)
c := newCLITest()
defer c.stop()

c.Run("debug kv put a 1 b 2 c 3")
c.Run("debug kv scan")
c.Run("debug kv revscan")
c.Run("debug kv del a c")
c.Run("debug kv get a")
c.Run("debug kv get b")
c.Run("debug kv inc c 1")
c.Run("debug kv inc c 10")
c.Run("debug kv inc c 100")
c.Run("debug kv inc c -- -60")
c.Run("debug kv inc c -- -9")
c.Run("debug kv scan")
c.Run("debug kv revscan")
c.Run("debug kv inc c b")
Output:

debug kv put a 1 b 2 c 3
debug kv scan
"a"	"1"
"b"	"2"
"c"	"3"
3 result(s)
debug kv revscan
"c"	"3"
"b"	"2"
"a"	"1"
3 result(s)
debug kv del a c
debug kv get a
"a" not found
debug kv get b
"2"
debug kv inc c 1
1
debug kv inc c 10
11
debug kv inc c 100
111
debug kv inc c -- -60
51
debug kv inc c -- -9
42
debug kv scan
"b"	"2"
"c"	42
2 result(s)
debug kv revscan
"c"	42
"b"	"2"
2 result(s)
debug kv inc c b
invalid increment: b: strconv.ParseInt: parsing "b": invalid syntax
Example (Cput)
c := newCLITest()
defer c.stop()

c.Run("debug kv put a 1 b 2 c 3 d 4")
c.Run("debug kv scan")
c.Run("debug kv cput e 5")
c.Run("debug kv cput b 3 2")
c.Run("debug kv scan")
Output:

debug kv put a 1 b 2 c 3 d 4
debug kv scan
"a"	"1"
"b"	"2"
"c"	"3"
"d"	"4"
4 result(s)
debug kv cput e 5
debug kv cput b 3 2
debug kv scan
"a"	"1"
"b"	"3"
"c"	"3"
"d"	"4"
"e"	"5"
5 result(s)
Example (Insecure)
s, err := serverutils.StartServerRaw(
	base.TestServerArgs{Insecure: true})
if err != nil {
	log.Fatalf(context.Background(), "Could not start server: %v", err)
}
defer s.Stopper().Stop()
c := cliTest{TestServer: s.(*server.TestServer), cleanupFunc: func() {}}

c.Run("debug kv put --insecure a 1 b 2")
c.Run("debug kv scan --insecure")
Output:

debug kv put --insecure a 1 b 2
debug kv scan --insecure
"a"	"1"
"b"	"2"
2 result(s)
Example (Logging)
c := newCLITest()
defer c.stop()

c.RunWithArgs([]string{"sql", "--alsologtostderr=false", "-e", "select 1"})
c.RunWithArgs([]string{"sql", "--log-backtrace-at=foo.go:1", "-e", "select 1"})
c.RunWithArgs([]string{"sql", "--log-dir=", "-e", "select 1"})
c.RunWithArgs([]string{"sql", "--logtostderr=true", "-e", "select 1"})
c.RunWithArgs([]string{"sql", "--verbosity=0", "-e", "select 1"})
c.RunWithArgs([]string{"sql", "--vmodule=foo=1", "-e", "select 1"})
Output:

sql --alsologtostderr=false -e select 1
1 row
1
1
sql --log-backtrace-at=foo.go:1 -e select 1
1 row
1
1
sql --log-dir= -e select 1
1 row
1
1
sql --logtostderr=true -e select 1
1 row
1
1
sql --verbosity=0 -e select 1
1 row
1
1
sql --vmodule=foo=1 -e select 1
1 row
1
1
Example (Max_results)
c := newCLITest()
defer c.stop()

c.Run("debug kv put a 1 b 2 c 3 d 4")
c.Run("debug kv scan --max-results=3")
c.Run("debug kv revscan --max-results=2")
c.Run("debug range split c")
c.Run("debug range split d")
c.Run("debug range ls --max-results=2")
Output:

debug kv put a 1 b 2 c 3 d 4
debug kv scan --max-results=3
"a"	"1"
"b"	"2"
"c"	"3"
3 result(s)
debug kv revscan --max-results=2
"d"	"4"
"c"	"3"
2 result(s)
debug range split c
debug range split d
debug range ls --max-results=2
/Min-"c" [1]
	0: node-id=1 store-id=1
"c"-"d" [6]
	0: node-id=1 store-id=1
2 result(s)
Example (Node)
c := newCLITest()
defer c.stop()

// Refresh time series data, which is required to retrieve stats.
if err := c.TestServer.WriteSummaries(); err != nil {
	log.Fatalf(context.Background(), "Couldn't write stats summaries: %s", err)
}

c.Run("node ls")
c.Run("node ls --pretty")
c.Run("node status 10000")
Output:

node ls
1 row
id
1
node ls --pretty
+----+
| id |
+----+
|  1 |
+----+
(1 row)
node status 10000
Error: node 10000 doesn't exist
Example (Quoted)
c := newCLITest()
defer c.stop()

c.Run(`debug kv put a\x00 日本語`)                                  // UTF-8 input text
c.Run(`debug kv put a\x01 \u65e5\u672c\u8a9e`)                   // explicit Unicode code points
c.Run(`debug kv put a\x02 \U000065e5\U0000672c\U00008a9e`)       // explicit Unicode code points
c.Run(`debug kv put a\x03 \xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e`) // explicit UTF-8 bytes
c.Run(`debug kv scan`)
c.Run(`debug kv get a\x00`)
c.Run(`debug kv del a\x00`)
c.Run(`debug kv inc 1\x01`)
c.Run(`debug kv get 1\x01`)
Output:

debug kv put a\x00 日本語
debug kv put a\x01 \u65e5\u672c\u8a9e
debug kv put a\x02 \U000065e5\U0000672c\U00008a9e
debug kv put a\x03 \xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e
debug kv scan
"a\x00"	"日本語"
"a\x01"	"日本語"
"a\x02"	"日本語"
"a\x03"	"日本語"
4 result(s)
debug kv get a\x00
"日本語"
debug kv del a\x00
debug kv inc 1\x01
1
debug kv get 1\x01
1
Example (Ranges)
c := newCLITest()
defer c.stop()

c.Run("debug kv put a 1 b 2 c 3 d 4")
c.Run("debug kv scan")
c.Run("debug kv revscan")
c.Run("debug range split c")
c.Run("debug range ls")
c.Run("debug kv scan")
c.Run("debug kv revscan")
c.Run("debug kv delrange a c")
c.Run("debug kv scan")
Output:

debug kv put a 1 b 2 c 3 d 4
debug kv scan
"a"	"1"
"b"	"2"
"c"	"3"
"d"	"4"
4 result(s)
debug kv revscan
"d"	"4"
"c"	"3"
"b"	"2"
"a"	"1"
4 result(s)
debug range split c
debug range ls
/Min-"c" [1]
	0: node-id=1 store-id=1
"c"-/Table/11 [6]
	0: node-id=1 store-id=1
/Table/11-/Table/12 [2]
	0: node-id=1 store-id=1
/Table/12-/Table/13 [3]
	0: node-id=1 store-id=1
/Table/13-/Table/14 [4]
	0: node-id=1 store-id=1
/Table/14-/Max [5]
	0: node-id=1 store-id=1
6 result(s)
debug kv scan
"a"	"1"
"b"	"2"
"c"	"3"
"d"	"4"
4 result(s)
debug kv revscan
"d"	"4"
"c"	"3"
"b"	"2"
"a"	"1"
4 result(s)
debug kv delrange a c
debug kv scan
"c"	"3"
"d"	"4"
2 result(s)
Example (Sql)
c := newCLITest()
defer c.stop()

c.RunWithArgs([]string{"sql", "-e", "create database t; create table t.f (x int, y int); insert into t.f values (42, 69)"})
c.RunWithArgs([]string{"sql", "-e", "select 3", "-e", "select * from t.f"})
c.RunWithArgs([]string{"sql", "-e", "begin", "-e", "select 3", "-e", "commit"})
c.RunWithArgs([]string{"sql", "-e", "select * from t.f"})
c.RunWithArgs([]string{"sql", "--execute=show databases"})
c.RunWithArgs([]string{"sql", "-e", "explain select 3"})
c.RunWithArgs([]string{"sql", "-e", "select 1; select 2"})
Output:

sql -e create database t; create table t.f (x int, y int); insert into t.f values (42, 69)
INSERT 1
sql -e select 3 -e select * from t.f
1 row
3
3
1 row
x	y
42	69
sql -e begin -e select 3 -e commit
BEGIN
1 row
3
3
COMMIT
sql -e select * from t.f
1 row
x	y
42	69
sql --execute=show databases
3 rows
Database
information_schema
system
t
sql -e explain select 3
1 row
Level	Type	Description
0	empty	-
sql -e select 1; select 2
1 row
1
1
1 row
2
2
Example (Sql_escape)
c := newCLITest()
defer c.stop()

c.RunWithArgs([]string{"sql", "-e", "create database t; create table t.t (s string, d string);"})
c.RunWithArgs([]string{"sql", "-e", "insert into t.t values (e'foo', 'printable ASCII')"})
c.RunWithArgs([]string{"sql", "-e", "insert into t.t values (e'\"foo', 'printable ASCII with quotes')"})
c.RunWithArgs([]string{"sql", "-e", "insert into t.t values (e'\\\\foo', 'printable ASCII with backslash')"})
c.RunWithArgs([]string{"sql", "-e", "insert into t.t values (e'foo\\x0abar', 'non-printable ASCII')"})
c.RunWithArgs([]string{"sql", "-e", "insert into t.t values ('κόσμε', 'printable UTF8')"})
c.RunWithArgs([]string{"sql", "-e", "insert into t.t values (e'\\xc3\\xb1', 'printable UTF8 using escapes')"})
c.RunWithArgs([]string{"sql", "-e", "insert into t.t values (e'\\x01', 'non-printable UTF8 string')"})
c.RunWithArgs([]string{"sql", "-e", "insert into t.t values (e'\\xdc\\x88\\x38\\x35', 'UTF8 string with RTL char')"})
c.RunWithArgs([]string{"sql", "-e", "insert into t.t values (e'\\xc3\\x28', 'non-UTF8 string')"})
c.RunWithArgs([]string{"sql", "-e", "insert into t.t values (e'a\\tb\\tc\\n12\\t123123213\\t12313', 'tabs')"})
c.RunWithArgs([]string{"sql", "-e", "select * from t.t"})
c.RunWithArgs([]string{"sql", "-e", "create table t.u (\"\"\"foo\" int, \"\\foo\" int, \"foo\nbar\" int, \"κόσμε\" int, \"܈85\" int)"})
c.RunWithArgs([]string{"sql", "-e", "insert into t.u values (0, 0, 0, 0, 0)"})
c.RunWithArgs([]string{"sql", "-e", "show columns from t.u"})
c.RunWithArgs([]string{"sql", "-e", "select * from t.u"})
c.RunWithArgs([]string{"sql", "--pretty", "-e", "select * from t.t"})
c.RunWithArgs([]string{"sql", "--pretty", "-e", "show columns from t.u"})
c.RunWithArgs([]string{"sql", "--pretty", "-e", "select * from t.u"})
Output:

sql -e create database t; create table t.t (s string, d string);
CREATE TABLE
sql -e insert into t.t values (e'foo', 'printable ASCII')
INSERT 1
sql -e insert into t.t values (e'"foo', 'printable ASCII with quotes')
INSERT 1
sql -e insert into t.t values (e'\\foo', 'printable ASCII with backslash')
INSERT 1
sql -e insert into t.t values (e'foo\x0abar', 'non-printable ASCII')
INSERT 1
sql -e insert into t.t values ('κόσμε', 'printable UTF8')
INSERT 1
sql -e insert into t.t values (e'\xc3\xb1', 'printable UTF8 using escapes')
INSERT 1
sql -e insert into t.t values (e'\x01', 'non-printable UTF8 string')
INSERT 1
sql -e insert into t.t values (e'\xdc\x88\x38\x35', 'UTF8 string with RTL char')
INSERT 1
sql -e insert into t.t values (e'\xc3\x28', 'non-UTF8 string')
pq: invalid UTF-8 byte sequence
insert into t.t values (e'\xc3\x28', 'non-UTF8 string')
                        ^

sql -e insert into t.t values (e'a\tb\tc\n12\t123123213\t12313', 'tabs')
INSERT 1
sql -e select * from t.t
9 rows
s	d
foo	printable ASCII
"\"foo"	printable ASCII with quotes
"\\foo"	printable ASCII with backslash
"foo\nbar"	non-printable ASCII
"\u03ba\u1f79\u03c3\u03bc\u03b5"	printable UTF8
"\u00f1"	printable UTF8 using escapes
"\x01"	non-printable UTF8 string
"\u070885"	UTF8 string with RTL char
"a\tb\tc\n12\t123123213\t12313"	tabs
sql -e create table t.u ("""foo" int, "\foo" int, "foo
bar" int, "κόσμε" int, "܈85" int)
CREATE TABLE
sql -e insert into t.u values (0, 0, 0, 0, 0)
INSERT 1
sql -e show columns from t.u
6 rows
Field	Type	Null	Default
"\"foo"	INT	true	NULL
"\\foo"	INT	true	NULL
"foo\nbar"	INT	true	NULL
"\u03ba\u1f79\u03c3\u03bc\u03b5"	INT	true	NULL
"\u070885"	INT	true	NULL
rowid	INT	false	unique_rowid()
sql -e select * from t.u
1 row
"\"foo"	"\\foo"	"foo\nbar"	"\u03ba\u1f79\u03c3\u03bc\u03b5"	"\u070885"
0	0	0	0	0
sql --pretty -e select * from t.t
+--------------------------------+--------------------------------+
|               s                |               d                |
+--------------------------------+--------------------------------+
| foo                            | printable ASCII                |
| "foo                           | printable ASCII with quotes    |
| \foo                           | printable ASCII with backslash |
| foo␤                           | non-printable ASCII            |
| bar                            |                                |
| κόσμε                          | printable UTF8                 |
| ñ                              | printable UTF8 using escapes   |
| "\x01"                         | non-printable UTF8 string      |
| ܈85                            | UTF8 string with RTL char      |
| a   b         c␤               | tabs                           |
| 12  123123213 12313            |                                |
+--------------------------------+--------------------------------+
(9 rows)
sql --pretty -e show columns from t.u
+----------+------+-------+----------------+
|  Field   | Type | Null  |    Default     |
+----------+------+-------+----------------+
| "foo     | INT  | true  | NULL           |
| \foo     | INT  | true  | NULL           |
| foo␤     | INT  | true  | NULL           |
| bar      |      |       |                |
| κόσμε    | INT  | true  | NULL           |
| ܈85      | INT  | true  | NULL           |
| rowid    | INT  | false | unique_rowid() |
+----------+------+-------+----------------+
(6 rows)
sql --pretty -e select * from t.u
+------+------+------------+-------+-----+
| "foo | \foo | "foo\nbar" | κόσμε | ܈85 |
+------+------+------------+-------+-----+
|    0 |    0 |          0 |     0 |   0 |
+------+------+------------+-------+-----+
(1 row)
Example (User)
c := newCLITest()
defer c.stop()

c.Run("user ls")
c.Run("user ls --pretty")
c.Run("user ls --pretty=false")
c.Run("user set foo --password=bar")
// Don't use get, since the output of hashedPassword is random.
// c.Run("user get foo")
c.Run("user ls --pretty")
c.Run("user rm foo")
c.Run("user ls --pretty")
Output:

user ls
0 rows
username
user ls --pretty
+----------+
| username |
+----------+
+----------+
(0 rows)
user ls --pretty=false
0 rows
username
user set foo --password=bar
INSERT 1
user ls --pretty
+----------+
| username |
+----------+
| foo      |
+----------+
(1 row)
user rm foo
DELETE 1
user ls --pretty
+----------+
| username |
+----------+
+----------+
(0 rows)
Example (Zone)
c := newCLITest()
defer c.stop()

c.Run("zone ls")
c.Run("zone set system --file=./testdata/zone_attrs.yaml")
c.Run("zone ls")
c.Run("zone get system.nonexistent")
c.Run("zone get system.lease")
c.Run("zone set system --file=./testdata/zone_range_max_bytes.yaml")
c.Run("zone get system")
c.Run("zone rm system")
c.Run("zone ls")
c.Run("zone rm .default")
c.Run("zone set .default --file=./testdata/zone_range_max_bytes.yaml")
c.Run("zone get system")
c.Run("zone set .default --disable-replication")
c.Run("zone get system")
Output:

zone ls
.default
zone set system --file=./testdata/zone_attrs.yaml
range_min_bytes: 1048576
range_max_bytes: 67108864
gc:
  ttlseconds: 86400
num_replicas: 1
constraints: [us-east-1a, ssd]
zone ls
.default
system
zone get system.nonexistent
system.nonexistent not found
zone get system.lease
system
range_min_bytes: 1048576
range_max_bytes: 67108864
gc:
  ttlseconds: 86400
num_replicas: 1
constraints: [us-east-1a, ssd]
zone set system --file=./testdata/zone_range_max_bytes.yaml
range_min_bytes: 1048576
range_max_bytes: 134217728
gc:
  ttlseconds: 86400
num_replicas: 3
constraints: [us-east-1a, ssd]
zone get system
system
range_min_bytes: 1048576
range_max_bytes: 134217728
gc:
  ttlseconds: 86400
num_replicas: 3
constraints: [us-east-1a, ssd]
zone rm system
DELETE 1
zone ls
.default
zone rm .default
unable to remove .default
zone set .default --file=./testdata/zone_range_max_bytes.yaml
range_min_bytes: 1048576
range_max_bytes: 134217728
gc:
  ttlseconds: 86400
num_replicas: 3
constraints: []
zone get system
.default
range_min_bytes: 1048576
range_max_bytes: 134217728
gc:
  ttlseconds: 86400
num_replicas: 3
constraints: []
zone set .default --disable-replication
range_min_bytes: 1048576
range_max_bytes: 134217728
gc:
  ttlseconds: 86400
num_replicas: 1
constraints: []
zone get system
.default
range_min_bytes: 1048576
range_max_bytes: 134217728
gc:
  ttlseconds: 86400
num_replicas: 1
constraints: []

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrorCode = 1

ErrorCode is the value to be used by main() as exit code in case of error. For most errors 1 is appropriate, but a signal termination can change this.

Functions

func Run

func Run(args []string) error

Run ...

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL