Skip to content

Commit

Permalink
Print execution plan information in console (#4)
Browse files Browse the repository at this point in the history
* some utils

* Refactor

* upgrade nebula go

* Use table library to print

* Print plan description

* Use go pretty v6

* Print graphviz dot string

* Print loop and select branch

* Set style of table writer

* Upgrade nebula-go and fix table writer config

* Refactor plan desc printer

* print dot graphviz

* Fix comments

* Refactor and cleanup

* Print execution plan title
  • Loading branch information
yixinglu authored Aug 3, 2020
1 parent 84db74a commit 68353d4
Show file tree
Hide file tree
Showing 14 changed files with 505 additions and 207 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
insert_final_newline = true
charset = utf-8
trim_trailing_whitespace = true
indent_style = space
indent_size = 2

[{Makefile,go.mod,go.sum,*.go}]
indent_style = tab
indent_size = 2
9 changes: 1 addition & 8 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,7 @@ jobs:
with:
go-version: 1.14
- name: build
run: |
go build
run: make
env:
GOOS: ${{ matrix.os }}
GOARCH: ${{ matrix.arch }}
- name: test
if: matrix.os == 'linux' && matrix.arch == 'amd64'
run: |
set -e
./nebula-console2.0 -e 'exit'
./nebula-console2.0 -f demo.nGQL
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
*.out

# Dependency directories (remove the comment below to include it)
# vendor/
vendor/

nebula-console
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ COPY . /usr/src

RUN cd /usr/src && go build

FROM centos:7
FROM golang:1.14.2

COPY --from=builder /usr/src/nebula-console /usr/bin
COPY --from=builder /usr/src/nebula-console /usr/bin/nebula-console
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

.PHONY: build vendorbuild clean fmt

default: build

build: clean fmt
go build -o nebula-console

vendorbuild: clean fmt
@go mod vendor && go build -mod vendor -o nebula-console

clean:
@rm -rf nebula-console vendor

fmt:
@find . -path vendor -prune -type f -iname '*.go' -exec go fmt {} \;
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ The console for Nebula Graph 2.0

# Build

Install golang by https://golang.org/doc/install, then try `go build`
Install golang by https://golang.org/doc/install, then build with following commands:

```shell
$ cd nebula-console
$ make
```

# Usage

Expand Down
104 changes: 13 additions & 91 deletions cli.go → cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* attached with Common Clause Condition 1.0, found in the LICENSES directory.
*/

package main
package cli

import (
"bufio"
Expand All @@ -14,111 +14,33 @@ import (
"os"
"path"

readline "github.com/vesoft-inc/readline"
"github.com/vesoft-inc/nebula-console/completer"

"github.com/vesoft-inc/readline"
)

const NebulaLabel = "nebula"

const ttyColorPrefix = "\033["
const ttyColorSuffix = "m"
const ttyColorRed = "31"
const ttyColorBold = "1"
const ttyColorReset = "0"

var completer = readline.NewPrefixCompleter(
// show
readline.PcItem("SHOW",
readline.PcItem("HOSTS"),
readline.PcItem("SPACES"),
readline.PcItem("PARTS"),
readline.PcItem("TAGS"),
readline.PcItem("EDGES"),
readline.PcItem("USERS"),
readline.PcItem("ROLES"),
readline.PcItem("USER"),
readline.PcItem("CONFIGS"),
),

// describe
readline.PcItem("DESCRIBE",
readline.PcItem("TAG"),
readline.PcItem("EDGE"),
readline.PcItem("SPACE"),
),
readline.PcItem("DESC",
readline.PcItem("TAG"),
readline.PcItem("EDGE"),
readline.PcItem("SPACE"),
),
// get configs
readline.PcItem("GET",
readline.PcItem("CONFIGS"),
),
// create
readline.PcItem("CREATE",
readline.PcItem("SPACE"),
readline.PcItem("TAG"),
readline.PcItem("EDGE"),
readline.PcItem("USER"),
),
// drop
readline.PcItem("DROP",
readline.PcItem("SPACE"),
readline.PcItem("TAG"),
readline.PcItem("EDGE"),
readline.PcItem("USER"),
),
// alter
readline.PcItem("ALTER",
readline.PcItem("USER"),
readline.PcItem("TAG"),
readline.PcItem("EDGE"),
),

// insert
readline.PcItem("INSERT",
readline.PcItem("VERTEX"),
readline.PcItem("EDGE"),
),
// update
readline.PcItem("UPDATE",
readline.PcItem("CONFIGS"),
readline.PcItem("VERTEX"),
readline.PcItem("EDGE"),
),
// upsert
readline.PcItem("UPSERT",
readline.PcItem("VERTEX"),
readline.PcItem("EDGE"),
),
// delete
readline.PcItem("DELETE",
readline.PcItem("VERTEX"),
readline.PcItem("EDGE"),
),

// grant
readline.PcItem("GRANT",
readline.PcItem("ROLE"),
),
// revoke
readline.PcItem("REVOKE",
readline.PcItem("ROLE"),
),
// change password
readline.PcItem("CHANGE",
readline.PcItem("PASSWORD"),
),
)

func promptString(space string, user string, isErr bool, isTTY bool) string {
prompt := ""
// (user@nebula) [(space)] >
// (user@nebula) [space] >
if isTTY {
prompt += fmt.Sprintf("%s%s%s", ttyColorPrefix, ttyColorBold, ttyColorSuffix)
}
if isTTY && isErr {
prompt += fmt.Sprintf("%s%s%s", ttyColorPrefix, ttyColorRed, ttyColorSuffix)
}
prompt += fmt.Sprintf("(%s@%s) [(%s)]> ", user, NebulaLabel, space)
spaceName := "(none)"
if len(space) > 0 {
spaceName = space
}
prompt += fmt.Sprintf("(%s@%s) [%s]> ", user, NebulaLabel, spaceName)
if isTTY {
prompt += fmt.Sprintf("%s%s%s", ttyColorPrefix, ttyColorReset, ttyColorSuffix)
}
Expand Down Expand Up @@ -146,7 +68,7 @@ func NewiCli(home string, user string) *iCli {
// See https://github.com/chzyer/readline/issues/169
Prompt: nil,
HistoryFile: path.Join(home, ".nebula_history"),
AutoComplete: completer,
AutoComplete: completer.NewCompleter(),
InterruptPrompt: "^C",
EOFPrompt: "",
HistorySearchFold: true,
Expand Down
99 changes: 99 additions & 0 deletions completer/completer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/* Copyright (c) 2020 vesoft inc. All rights reserved.
*
* This source code is licensed under Apache 2.0 License,
* attached with Common Clause Condition 1.0, found in the LICENSES directory.
*/

package completer

import "github.com/vesoft-inc/readline"

var prefixCompleter = readline.NewPrefixCompleter(
// show
readline.PcItem("SHOW",
readline.PcItem("HOSTS"),
readline.PcItem("SPACES"),
readline.PcItem("PARTS"),
readline.PcItem("TAGS"),
readline.PcItem("EDGES"),
readline.PcItem("USERS"),
readline.PcItem("ROLES"),
readline.PcItem("USER"),
readline.PcItem("CONFIGS"),
),

// describe
readline.PcItem("DESCRIBE",
readline.PcItem("TAG"),
readline.PcItem("EDGE"),
readline.PcItem("SPACE"),
),
readline.PcItem("DESC",
readline.PcItem("TAG"),
readline.PcItem("EDGE"),
readline.PcItem("SPACE"),
),
// get configs
readline.PcItem("GET",
readline.PcItem("CONFIGS"),
),
// create
readline.PcItem("CREATE",
readline.PcItem("SPACE"),
readline.PcItem("TAG"),
readline.PcItem("EDGE"),
readline.PcItem("USER"),
),
// drop
readline.PcItem("DROP",
readline.PcItem("SPACE"),
readline.PcItem("TAG"),
readline.PcItem("EDGE"),
readline.PcItem("USER"),
),
// alter
readline.PcItem("ALTER",
readline.PcItem("USER"),
readline.PcItem("TAG"),
readline.PcItem("EDGE"),
),

// insert
readline.PcItem("INSERT",
readline.PcItem("VERTEX"),
readline.PcItem("EDGE"),
),
// update
readline.PcItem("UPDATE",
readline.PcItem("CONFIGS"),
readline.PcItem("VERTEX"),
readline.PcItem("EDGE"),
),
// upsert
readline.PcItem("UPSERT",
readline.PcItem("VERTEX"),
readline.PcItem("EDGE"),
),
// delete
readline.PcItem("DELETE",
readline.PcItem("VERTEX"),
readline.PcItem("EDGE"),
),

// grant
readline.PcItem("GRANT",
readline.PcItem("ROLE"),
),
// revoke
readline.PcItem("REVOKE",
readline.PcItem("ROLE"),
),
// change password
readline.PcItem("CHANGE",
readline.PcItem("PASSWORD"),
),
)

func NewCompleter() *readline.PrefixCompleter {
return prefixCompleter
}
10 changes: 8 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
module vesoft-inc/nebula-console
module github.com/vesoft-inc/nebula-console

go 1.13

require (
github.com/vesoft-inc/nebula-go/v2 v2.0.0-20200722013035-73eebb836e7e
github.com/chzyer/logex v1.1.10 // indirect
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 // indirect
github.com/jedib0t/go-pretty/v6 v6.0.4
github.com/stretchr/testify v1.3.0 // indirect
github.com/vesoft-inc/nebula-go/v2 v2.0.0-20200730062750-d87c9abe1422
github.com/vesoft-inc/readline v0.0.0-20200707112557-889240450af4
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae // indirect
)
25 changes: 23 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/facebook/fbthrift v0.0.0-20190922225929-2f9839604e25 h1:dezRDs9oGYxeavyvcNg/Js+dK6kIvfzERoJ7K8Xkv14=
github.com/facebook/fbthrift v0.0.0-20190922225929-2f9839604e25/go.mod h1:2tncLx5rmw69e5kMBv/yJneERbzrr1yr5fdlnTbu8lU=
github.com/vesoft-inc/nebula-go/v2 v2.0.0-20200722013035-73eebb836e7e h1:CV/gYc4QM4fyfpxfShsxQ8GgG2vu6u1fP9mhtIB17Sw=
github.com/vesoft-inc/nebula-go/v2 v2.0.0-20200722013035-73eebb836e7e/go.mod h1:92I8vrIc2Rk7/oJO+1hTgjNhHiYfnsW2uu3Ofh0ECnI=
github.com/jedib0t/go-pretty/v6 v6.0.4 h1:7WaHUeKo5yc2vABlsh30p4VWxQoXaWktBY/nR/2qnPg=
github.com/jedib0t/go-pretty/v6 v6.0.4/go.mod h1:MTr6FgcfNdnN5wPVBzJ6mhJeDyiF0yBvS2TMXEV/XSU=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/vesoft-inc/nebula-go/v2 v2.0.0-20200730062750-d87c9abe1422 h1:cPIBBtmtXq9BvK4xh/lq9Yr3yg5ksqFScbREOFYRKxA=
github.com/vesoft-inc/nebula-go/v2 v2.0.0-20200730062750-d87c9abe1422/go.mod h1:92I8vrIc2Rk7/oJO+1hTgjNhHiYfnsW2uu3Ofh0ECnI=
github.com/vesoft-inc/readline v0.0.0-20200707112557-889240450af4 h1:DiyiidZ9FBSwOZfslQeIPeCUo7AjJ59bj3UaTQEY7po=
github.com/vesoft-inc/readline v0.0.0-20200707112557-889240450af4/go.mod h1:E6VDTX2OSL0so+MQj23uMHpp24E2gqbl5nVOSviDIkU=
golang.org/x/sys v0.0.0-20180816055513-1c9583448a9c/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae h1:Ih9Yo4hSPImZOpfGuA4bR/ORKTAbhZo2AbWNRCnevdo=
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Loading

0 comments on commit 68353d4

Please sign in to comment.