Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinjqiu committed Aug 1, 2018
0 parents commit 16b81e7
Show file tree
Hide file tree
Showing 586 changed files with 227,958 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, build with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
promcli
198 changes: 198 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Gopkg.toml example
#
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
#
# [prune]
# non-go = false
# go-tests = true
# unused-packages = true


[prune]
go-tests = true
unused-packages = true

[[constraint]]
name = "github.com/c-bata/go-prompt"
version = "0.2.2"

[[constraint]]
name = "github.com/prometheus/prometheus"
version = "2.3.2"
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build:
go build

proxy:
ln -s $(pwd)/_proxy/proxy.go $(pwd)/vendor/github.com/prometheus/prometheus/promql/proxy.go
48 changes: 48 additions & 0 deletions _proxy/proxy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package promql

import (
"log"
"github.com/prometheus/prometheus/storage"
"github.com/prometheus/prometheus/util/testutil"
)

type TestCommand = testCommand

type t struct {}
func (t t) Fatal(args ...interface{}) {
log.Fatal(args)
}

func (t t) Fatalf(format string, args ...interface{}) {
log.Fatalf(format, args)
}

func ParseTestCommand(input string) ([]TestCommand, error) {
t := Test{
T: t{},
cmds: []TestCommand{},
}

err := t.parse(input)
if err != nil {
return t.cmds, err
}
return t.cmds, nil
}

func ExecuteTestCommand(tc TestCommand, storage *storage.Storage) (*storage.Storage, error) {
t := Test{
T: t{},
storage: *storage,
cmds: []TestCommand{tc},
}
return &t.storage, t.exec(tc)
}

func NewTestStorage() *storage.Storage {
t := Test{
T: t{},
}
storage := testutil.NewStorage(t)
return &storage
}
43 changes: 43 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package main

import (
"github.com/c-bata/go-prompt"
"fmt"
"github.com/prometheus/prometheus/promql"
)

func executor(input string) {
storage := promql.NewTestStorage()
fmt.Println("Your input: " + input)
cmds, err := promql.ParseTestCommand(input)
if err != nil {
panic(err)
}
fmt.Println(cmds)
for _, cmd := range cmds {
storage, err = promql.ExecuteTestCommand(cmd, storage)
if err != nil {
panic(err)
}
}
}

func completer(d prompt.Document) []prompt.Suggest {
s := []prompt.Suggest{
{Text: "users", Description: "Users table"},
{Text: "articles", Description: "Articles table"},
{Text: "comments", Description: "Comments table"},
}
return prompt.FilterHasPrefix(s, d.GetWordBeforeCursor(), true)
}

func main() {
p := prompt.New(
executor,
completer,
prompt.OptionPrefix(">>> "),
prompt.OptionTitle("PromCLI"),
)

p.Run()
}
20 changes: 20 additions & 0 deletions vendor/github.com/beorn7/perks/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 16b81e7

Please sign in to comment.