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) ¶
c := cliTest{cleanupFunc: func() {}} c.TestServer = &server.TestServer{} c.Ctx = server.NewTestContext() c.Ctx.Insecure = true if err := c.Start(); err != nil { log.Fatalf("Could not start server: %v", err) } defer c.stop() 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("Couldn't write stats summaries: %s", err) } c.Run("node ls") c.Run("node status 10000")
Output: node ls +----+ | id | +----+ | 1 | +----+ 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 2 rows Database 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\\x0a', '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", "select * from t.t"})
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\x0a', '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') INSERT 1 sql -e select * from t.t 7 rows s d foo printable ASCII "foo\n" 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 "\xc3(" non-UTF8 string
Example (User) ¶
c := newCLITest() defer c.stop() c.Run("user ls") 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") c.Run("user rm foo") c.Run("user ls")
Output: user ls +----------+ | username | +----------+ +----------+ user set foo --password=bar INSERT 1 user ls +----------+ | username | +----------+ | foo | +----------+ user rm foo DELETE 1 user ls +----------+ | username | +----------+ +----------+
Example (Zone) ¶
c := newCLITest() defer c.stop() const zone1 = `replicas: - attrs: [us-east-1a,ssd]` const zone2 = `range_max_bytes: 134217728` c.Run("zone ls") // Call RunWithArgs to bypass the "split-by-whitespace" arg builder. c.RunWithArgs([]string{"zone", "set", "system", zone1}) c.Run("zone ls") c.Run("zone get system.nonexistent") c.Run("zone get system.lease") c.RunWithArgs([]string{"zone", "set", "system", zone2}) c.Run("zone get system") c.Run("zone rm system") c.Run("zone ls") c.Run("zone rm .default") c.RunWithArgs([]string{"zone", "set", ".default", zone2}) c.Run("zone get system")
Output: zone ls .default zone set system replicas: - attrs: [us-east-1a,ssd] INSERT 1 zone ls .default system zone get system.nonexistent system.nonexistent not found zone get system.lease system replicas: - attrs: [us-east-1a, ssd] range_min_bytes: 1048576 range_max_bytes: 67108864 gc: ttlseconds: 86400 zone set system range_max_bytes: 134217728 UPDATE 1 zone get system system replicas: - attrs: [us-east-1a, ssd] range_min_bytes: 1048576 range_max_bytes: 134217728 gc: ttlseconds: 86400 zone rm system DELETE 1 zone ls .default zone rm .default unable to remove .default zone set .default range_max_bytes: 134217728 UPDATE 1 zone get system .default replicas: - attrs: [] range_min_bytes: 1048576 range_max_bytes: 134217728 gc: ttlseconds: 86400
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Context ¶
type Context struct { // Embed the server context. server.Context // contains filtered or unexported fields }
Context contains global settings for the command-line client.
func (*Context) InitDefaults ¶
func (ctx *Context) InitDefaults()
InitDefaults sets up the default values for a Context.
Click to show internal directories.
Click to hide internal directories.