Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
rename cliaction to action in typiobj + tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
imantung committed Oct 31, 2019
1 parent db0341e commit c7b0750
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 23 deletions.
1 change: 0 additions & 1 deletion EXPERIMENTAL/typicmd/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ type application struct {

func (a application) Run(ctx *cli.Context) (err error) {
di := dig.New()
defer a.Close(di)
runkit.GracefulShutdown(func() error {
return a.Close(di)
})
Expand Down
15 changes: 2 additions & 13 deletions EXPERIMENTAL/typiobj/cli.go → EXPERIMENTAL/typiobj/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,8 @@ import (
"go.uber.org/dig"
)

// CommandLiner responsible to give command
type CommandLiner interface {
CommandLine() cli.Command
}

// IsCommandLiner return true if object implementation of CommandLiner
func IsCommandLiner(obj interface{}) (ok bool) {
_, ok = obj.(CommandLiner)
return
}

// CliAction to return cli action
func CliAction(p interface{}, fn interface{}) func(ctx *cli.Context) error {
// Action to return cli action
func Action(p interface{}, fn interface{}) func(ctx *cli.Context) error {
return func(ctx *cli.Context) (err error) {
c := dig.New()
defer func() {
Expand Down
16 changes: 16 additions & 0 deletions EXPERIMENTAL/typiobj/commandliner.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package typiobj

import (
"github.com/urfave/cli"
)

// CommandLiner responsible to give command
type CommandLiner interface {
CommandLine() cli.Command
}

// IsCommandLiner return true if object implementation of CommandLiner
func IsCommandLiner(obj interface{}) (ok bool) {
_, ok = obj.(CommandLiner)
return
}
14 changes: 7 additions & 7 deletions pkg/typpostgres/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ func (p postgresModule) CommandLine() cli.Command {
Usage: "Postgres Database Tool",
Before: envkit.CliLoadEnvFile,
Subcommands: []cli.Command{
{Name: "create", Usage: "Create New Database", Action: typiobj.CliAction(p, p.createDB)},
{Name: "drop", Usage: "Drop Database", Action: typiobj.CliAction(p, p.dropDB)},
{Name: "migrate", Usage: "Migrate Database", Action: typiobj.CliAction(p, p.migrateDB)},
{Name: "rollback", Usage: "Rollback Database", Action: typiobj.CliAction(p, p.rollbackDB)},
{Name: "seed", Usage: "Database Seeding", Action: typiobj.CliAction(p, p.seedDB)},
{Name: "console", Usage: "PostgreSQL interactive terminal", Action: typiobj.CliAction(p, p.console)},
{Name: "create", Usage: "Create New Database", Action: typiobj.Action(p, p.createDB)},
{Name: "drop", Usage: "Drop Database", Action: typiobj.Action(p, p.dropDB)},
{Name: "migrate", Usage: "Migrate Database", Action: typiobj.Action(p, p.migrateDB)},
{Name: "rollback", Usage: "Rollback Database", Action: typiobj.Action(p, p.rollbackDB)},
{Name: "seed", Usage: "Database Seeding", Action: typiobj.Action(p, p.seedDB)},
{Name: "console", Usage: "PostgreSQL interactive terminal", Action: typiobj.Action(p, p.console)},
},
}
}
Expand Down Expand Up @@ -89,7 +89,7 @@ func (p postgresModule) openConnection(cfg *Config) (db *sql.DB, err error) {
}

func (postgresModule) closeConnection(db *sql.DB) error {
log.Info("Close postgres connection")
fmt.Println("Close postgres connection")
return db.Close()
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/typredis/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (r redisModule) CommandLine() cli.Command {
Usage: "Redis Utility Tool",
Before: envkit.CliLoadEnvFile,
Subcommands: []cli.Command{
{Name: "console", ShortName: "c", Action: typiobj.CliAction(r, r.console)},
{Name: "console", ShortName: "c", Action: typiobj.Action(r, r.console)},
},
}
}
Expand Down Expand Up @@ -79,6 +79,7 @@ func (redisModule) connect(cfg *Config) (client *redis.Client, err error) {
}

func (redisModule) disconnect(client *redis.Client) (err error) {
fmt.Println("Redis Client close")
return client.Close()
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/typserver/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package typserver

import (
"context"
"fmt"
"time"

"github.com/kelseyhightower/envconfig"
Expand Down Expand Up @@ -68,7 +69,7 @@ func (s serverModule) Create(cfg *Config) *echo.Echo {

// Shutdown the server
func (s serverModule) Shutdown(server *echo.Echo) error {
log.Info("Server is shutting down")
fmt.Println("Server is shutting down")
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
return server.Shutdown(ctx)
Expand Down

0 comments on commit c7b0750

Please sign in to comment.