Documentation ¶
Overview ¶
Example (Basic) ¶
c := newCLITest() defer c.stop() c.Run("kv put a 1 b 2 c 3") c.Run("kv scan") c.Run("kv revscan") c.Run("kv del a c") c.Run("kv get a") c.Run("kv get b") c.Run("kv inc c 1") c.Run("kv inc c 10") c.Run("kv inc c 100") c.Run("kv inc c -- -60") c.Run("kv inc c -- -9") c.Run("kv scan") c.Run("kv revscan") c.Run("kv inc c b")
Output: kv put a 1 b 2 c 3 kv scan "a" "1" "b" "2" "c" "3" 3 result(s) kv revscan "c" "3" "b" "2" "a" "1" 3 result(s) kv del a c kv get a "a" not found kv get b "2" kv inc c 1 1 kv inc c 10 11 kv inc c 100 111 kv inc c -- -60 51 kv inc c -- -9 42 kv scan "b" "2" "c" 42 2 result(s) kv revscan "c" 42 "b" "2" 2 result(s) kv inc c b invalid increment: b: strconv.ParseInt: parsing "b": invalid syntax
Example (Cput) ¶
c := newCLITest() defer c.stop() c.Run("kv put a 1 b 2 c 3 d 4") c.Run("kv scan") c.Run("kv cput e 5") c.Run("kv cput b 3 2") c.Run("kv scan")
Output: kv put a 1 b 2 c 3 d 4 kv scan "a" "1" "b" "2" "c" "3" "d" "4" 4 result(s) kv cput e 5 kv cput b 3 2 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("kv --insecure put a 1 b 2") c.Run("kv --insecure scan")
Output: kv --insecure put a 1 b 2 kv --insecure scan "a" "1" "b" "2" 2 result(s)
Example (Logging) ¶
c := newCLITest() defer c.stop() c.Run("kv --alsologtostderr=false scan") c.Run("kv --log-backtrace-at=foo.go:1 scan") c.Run("kv --log-dir='' scan") c.Run("kv --logtostderr=true scan") c.Run("kv --verbosity=0 scan") c.Run("kv --vmodule=foo=1 scan")
Output: kv --alsologtostderr=false scan 0 result(s) kv --log-backtrace-at=foo.go:1 scan 0 result(s) kv --log-dir='' scan 0 result(s) kv --logtostderr=true scan 0 result(s) kv --verbosity=0 scan 0 result(s) kv --vmodule=foo=1 scan 0 result(s)
Example (Max_results) ¶
c := newCLITest() defer c.stop() c.Run("kv put a 1 b 2 c 3 d 4") c.Run("kv scan --max-results=3") c.Run("kv revscan --max-results=2") c.Run("range split c") c.Run("range split d") c.Run("range ls --max-results=2")
Output: kv put a 1 b 2 c 3 d 4 kv scan --max-results=3 "a" "1" "b" "2" "c" "3" 3 result(s) kv revscan --max-results=2 "d" "4" "c" "3" 2 result(s) range split c range split d range ls --max-results=2 /Min-"c" [1] 0: node-id=1 store-id=1 "c"-"d" [5] 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(`kv put a\x00 日本語`) // UTF-8 input text c.Run(`kv put a\x01 \u65e5\u672c\u8a9e`) // explicit Unicode code points c.Run(`kv put a\x02 \U000065e5\U0000672c\U00008a9e`) // explicit Unicode code points c.Run(`kv put a\x03 \xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e`) // explicit UTF-8 bytes c.Run(`kv scan`) c.Run(`kv get a\x00`) c.Run(`kv del a\x00`) c.Run(`kv inc 1\x01`) c.Run(`kv get 1\x01`)
Output: kv put a\x00 日本語 kv put a\x01 \u65e5\u672c\u8a9e kv put a\x02 \U000065e5\U0000672c\U00008a9e kv put a\x03 \xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e kv scan "a\x00" "日本語" "a\x01" "日本語" "a\x02" "日本語" "a\x03" "日本語" 4 result(s) kv get a\x00 "日本語" kv del a\x00 kv inc 1\x01 1 kv get 1\x01 1
Example (Ranges) ¶
c := newCLITest() defer c.stop() c.Run("kv put a 1 b 2 c 3 d 4") c.Run("kv scan") c.Run("kv revscan") c.Run("range split c") c.Run("range ls") c.Run("kv scan") c.Run("kv revscan") c.Run("range merge b") c.Run("range ls") c.Run("kv scan") c.Run("kv revscan") c.Run("kv delrange a c") c.Run("kv scan")
Output: kv put a 1 b 2 c 3 d 4 kv scan "a" "1" "b" "2" "c" "3" "d" "4" 4 result(s) kv revscan "d" "4" "c" "3" "b" "2" "a" "1" 4 result(s) range split c range ls /Min-"c" [1] 0: node-id=1 store-id=1 "c"-/Table/11 [5] 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-/Max [4] 0: node-id=1 store-id=1 5 result(s) kv scan "a" "1" "b" "2" "c" "3" "d" "4" 4 result(s) kv revscan "d" "4" "c" "3" "b" "2" "a" "1" 4 result(s) range merge b range ls /Min-/Table/11 [1] 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-/Max [4] 0: node-id=1 store-id=1 4 result(s) kv scan "a" "1" "b" "2" "c" "3" "d" "4" 4 result(s) kv revscan "d" "4" "c" "3" "b" "2" "a" "1" 4 result(s) kv delrange a c 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", "select * from t.f"}) c.RunWithArgs([]string{"sql", "-e", "begin", "select 3", "commit"}) c.RunWithArgs([]string{"sql", "-e", "select * from t.f"}) c.RunWithArgs([]string{"sql", "-e", "show databases"}) c.RunWithArgs([]string{"sql", "-e", "explain select 3"})
Output: sql -e create database t; create table t.f (x int, y int); insert into t.f values (42, 69) OK sql -e select 3 select * from t.f 1 row 3 3 1 row x y 42 69 sql -e begin select 3 commit OK 1 row 3 3 OK sql -e select * from t.f 1 row x y 42 69 sql -e show databases 2 rows Database system t sql -e explain select 3 1 row Level Type Description 0 empty -
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 OK user ls +----------+ | username | +----------+ | foo | +----------+ user rm foo OK user ls +----------+ | username | +----------+ +----------+
Example (Zone) ¶
c := newCLITest() defer c.stop() zone100 := `replicas: - attrs: [us-east-1a,ssd] - attrs: [us-east-1b,ssd] - attrs: [us-west-1b,ssd] range_min_bytes: 8388608 range_max_bytes: 67108864 ` c.Run("zone ls") // Call RunWithArgs to bypass the "split-by-whitespace" arg builder. c.RunWithArgs([]string{"zone", "set", "100", zone100}) c.Run("zone ls") c.Run("zone get 100") c.Run("zone rm 100") c.Run("zone ls")
Output: zone ls zone set 100 replicas: - attrs: [us-east-1a,ssd] - attrs: [us-east-1b,ssd] - attrs: [us-west-1b,ssd] range_min_bytes: 8388608 range_max_bytes: 67108864 OK zone ls Object 100: replicas: - attrs: [us-east-1a, ssd] - attrs: [us-east-1b, ssd] - attrs: [us-west-1b, ssd] range_min_bytes: 8388608 range_max_bytes: 67108864 gc: ttlseconds: 0 zone get 100 replicas: - attrs: [us-east-1a, ssd] - attrs: [us-east-1b, ssd] - attrs: [us-west-1b, ssd] range_min_bytes: 8388608 range_max_bytes: 67108864 gc: ttlseconds: 0 zone rm 100 OK zone ls
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 // OneShotSQL indicates the SQL client should run the command-line // statement(s) and terminate directly, without presenting a REPL to // the user. OneShotSQL bool }
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.