Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flat package #41

Merged
merged 9 commits into from
May 4, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Moved domain/infrastructure/application packages
  • Loading branch information
takashabe committed May 4, 2019
commit 8125a05823692abb3f32291c5a59bbc228e80629
4 changes: 2 additions & 2 deletions cmd/btcli/btcli.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"os"

"github.com/takashabe/btcli/pkg/interfaces"
"github.com/takashabe/btcli/pkg/cmd/interactive"
)

// App version
Expand All @@ -13,7 +13,7 @@ var (
)

func main() {
cli := &interfaces.CLI{
cli := &interactive.CLI{
OutStream: os.Stdout,
ErrStream: os.Stderr,
Version: Version,
Expand Down
43 changes: 0 additions & 43 deletions pkg/application/rows.go

This file was deleted.

24 changes: 0 additions & 24 deletions pkg/application/tables.go

This file was deleted.

9 changes: 5 additions & 4 deletions pkg/cmd/interactive/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

prompt "github.com/c-bata/go-prompt"
"github.com/takashabe/btcli/pkg/bigtable"
"github.com/takashabe/btcli/pkg/evaluator/cbt"
)

// Command defines command describe and runner
Expand All @@ -26,13 +27,13 @@ var commands = []Command{
Name: "ls",
Description: "List tables",
Usage: "ls",
Runner: doLS,
Runner: cbt.DoLS,
},
{
Name: "count",
Description: "Count table rows",
Usage: "count <table>",
Runner: doCount,
Runner: cbt.DoCount,
},
{
Name: "lookup",
Expand All @@ -41,7 +42,7 @@ var commands = []Command{
version Read only latest <n> columns
decode Decode big-endian value
decode-columns Decode big-endian value with columns. <column_name:<string|int|float>[,<column_name:...>]`,
Runner: doLookup,
Runner: cbt.DoLookup,
},
{
Name: "read",
Expand All @@ -57,7 +58,7 @@ var commands = []Command{
to Read older cells than this unittime
decode Decode big-endian value
decode-columns Decode big-endian value with columns. <column_name:<string|int|float>[,<column_name:...>]`,
Runner: doRead,
Runner: cbt.DoRead,
},

// btcli commands
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/interactive/completer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"strings"

prompt "github.com/c-bata/go-prompt"
"github.com/takashabe/btcli/pkg/application"
"github.com/takashabe/btcli/pkg/bigtable"
)

// Completer provides completion command handler
type Completer struct {
tableInteractor *application.TableInteractor
client bigtable.Client
}

// Do provide completion to prompt
Expand Down Expand Up @@ -94,7 +94,7 @@ func filterDuplicateCommands(args []string, subcommands []prompt.Suggest) []prom
}

func (c *Completer) getTableSuggestions() []prompt.Suggest {
tbls, err := c.tableInteractor.GetTables(context.Background())
tbls, err := c.client.Tables(context.Background())
if err != nil {
return []prompt.Suggest{}
}
Expand Down
34 changes: 13 additions & 21 deletions pkg/cmd/interactive/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (

// Avoid to circular dependencies
var (
doHelpFn func(context.Context, *Executor, ...string)
doHelpFn func(context.Context, bigtable.Client, ...string)
)

func doHelp(ctx context.Context, e *Executor, args ...string) {
doHelpFn(ctx, e, args...)
func doHelp(ctx context.Context, client bigtable.Client, args ...string) {
doHelpFn(ctx, client, args...)
}

func init() {
Expand All @@ -25,9 +25,8 @@ func init() {

// Executor provides exec command handler
type Executor struct {
outStream io.Writer
errStream io.Writer
history io.Writer
client bigtable.Client
history io.Writer
}

// Do provides execute command
Expand All @@ -37,12 +36,6 @@ func (e *Executor) Do(s string) {
return
}

// TODO: wip
client, _ := bigtable.NewClient("", "",
bigtable.WithOutStream(e.outStream),
bigtable.WithErrStream(e.errStream),
)

ctx := context.Background()
args := strings.Split(s, " ")
cmd := args[0]
Expand All @@ -53,30 +46,29 @@ func (e *Executor) Do(s string) {
fmt.Fprintln(e.history, strings.Join(args, " "))
}

// TODO: extract args[0]
c.Runner(ctx, client, args...)
c.Runner(ctx, e.client, args[1:]...)
return
}
}
fmt.Fprintf(e.errStream, "Unknown command: %s\n", cmd)
fmt.Fprintf(e.client.ErrStream(), "Unknown command: %s\n", cmd)
}

func doExit(ctx context.Context, e *Executor, args ...string) {
fmt.Fprintln(e.outStream, "Bye!")
func doExit(ctx context.Context, client bigtable.Client, args ...string) {
fmt.Fprintln(client.OutStream(), "Bye!")
os.Exit(0)
}

func lazyDoHelp(ctx context.Context, e *Executor, args ...string) {
func lazyDoHelp(ctx context.Context, client bigtable.Client, args ...string) {
if len(args) == 1 {
usage(e.outStream)
usage(client.OutStream())
return
}
cmd := args[1]
for _, c := range commands {
if c.Name == cmd {
fmt.Fprintln(e.outStream, c.Usage)
fmt.Fprintln(client.OutStream(), c.Usage)
return
}
}
fmt.Fprintf(e.errStream, "Unknown command: %s\n", cmd)
fmt.Fprintf(client.ErrStream(), "Unknown command: %s\n", cmd)
}
Loading