Skip to content

Commit

Permalink
Pass the store to the run command.
Browse files Browse the repository at this point in the history
  • Loading branch information
xllora committed Feb 25, 2016
1 parent 8dfb83e commit 4811726
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion tools/vcli/bw/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
// Registration of the available commands. Please keep sorted.
var cmds = []*command.Command{
assert.New(memory.NewStore(), literal.DefaultBuilder()),
run.New(),
run.New(memory.NewStore()),
version.New(),
}

Expand Down
10 changes: 4 additions & 6 deletions tools/vcli/bw/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ import (
"github.com/google/badwolf/bql/semantic"
"github.com/google/badwolf/bql/table"
"github.com/google/badwolf/storage"
"github.com/google/badwolf/storage/memory"
"github.com/google/badwolf/tools/vcli/bw/command"
"github.com/google/badwolf/tools/vcli/bw/common"
)

// New creates the help command.
func New() *command.Command {
func New(store storage.Store) *command.Command {
cmd := &command.Command{
UsageLine: "run [--channel_size=123] file_path",
Short: "runs BQL statements.",
Expand All @@ -44,13 +43,13 @@ sequentially.
`,
}
cmd.Run = func(ctx context.Context, args []string) int {
return runCommand(ctx, cmd, args)
return runCommand(ctx, cmd, args, store)
}
return cmd
}

// runCommand runs all the BQL statements available in the file.
func runCommand(ctx context.Context, cmd *command.Command, args []string) int {
func runCommand(ctx context.Context, cmd *command.Command, args []string, store storage.Store) int {
if len(args) < 3 {
fmt.Fprintf(os.Stderr, "Missing required file path. ")
cmd.Usage()
Expand All @@ -72,10 +71,9 @@ func runCommand(ctx context.Context, cmd *command.Command, args []string) int {
return 2
}
fmt.Printf("Processing file %s\n\n", args[2])
s := memory.DefaultStore
for idx, stm := range lines {
fmt.Printf("Processing statement (%d/%d):\n%s\n\n", idx+1, len(lines), stm)
tbl, err := runBQL(ctx, stm, s, chanSize)
tbl, err := runBQL(ctx, stm, store, chanSize)
if err != nil {
fmt.Printf("[FAIL] %v\n\n", err)
continue
Expand Down

0 comments on commit 4811726

Please sign in to comment.