Switch to codegangsta/cli to be inline with micro
This commit is contained in:
parent
8bc2473989
commit
480165695c
58
cmd/cmd.go
58
cmd/cmd.go
@ -1,36 +1,33 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"os"
|
||||||
|
"text/tabwriter"
|
||||||
|
"text/template"
|
||||||
|
|
||||||
"github.com/asim/go-micro/registry"
|
"github.com/asim/go-micro/registry"
|
||||||
"github.com/asim/go-micro/server"
|
"github.com/asim/go-micro/server"
|
||||||
"github.com/asim/go-micro/store"
|
"github.com/asim/go-micro/store"
|
||||||
|
"github.com/codegangsta/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
flagBindAddress string
|
Flags = []cli.Flag{
|
||||||
flagRegistry string
|
cli.StringFlag{Name: "bind_address", Value: ":0", Usage: "Bind address for the server. 127.0.0.1:8080"},
|
||||||
flagStore string
|
cli.StringFlag{Name: "registry", Value: "consul", Usage: "Registry for discovery. kubernetes, consul, etc"},
|
||||||
|
cli.StringFlag{Name: "store", Value: "consul", Usage: "Store used as a basic key/value store using consul, memcached, etc"},
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func Setup(c *cli.Context) error {
|
||||||
flag.StringVar(&flagBindAddress, "bind_address", ":0", "Bind address for the server. 127.0.0.1:8080")
|
server.Address = c.String("bind_address")
|
||||||
flag.StringVar(&flagRegistry, "registry", "consul", "Registry for discovery. kubernetes, consul, etc")
|
|
||||||
flag.StringVar(&flagStore, "store", "consul", "Store used as a basic key/value store using consul, memcached, etc")
|
|
||||||
}
|
|
||||||
|
|
||||||
func Init() {
|
switch c.String("registry") {
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
server.Address = flagBindAddress
|
|
||||||
|
|
||||||
switch flagRegistry {
|
|
||||||
case "kubernetes":
|
case "kubernetes":
|
||||||
registry.DefaultRegistry = registry.NewKubernetesRegistry()
|
registry.DefaultRegistry = registry.NewKubernetesRegistry()
|
||||||
}
|
}
|
||||||
|
|
||||||
switch flagStore {
|
switch c.String("store") {
|
||||||
case "memcached":
|
case "memcached":
|
||||||
store.DefaultStore = store.NewMemcacheStore()
|
store.DefaultStore = store.NewMemcacheStore()
|
||||||
case "memory":
|
case "memory":
|
||||||
@ -38,4 +35,33 @@ func Init() {
|
|||||||
case "etcd":
|
case "etcd":
|
||||||
store.DefaultStore = store.NewEtcdStore()
|
store.DefaultStore = store.NewEtcdStore()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func Init() {
|
||||||
|
cli.AppHelpTemplate = `
|
||||||
|
GLOBAL OPTIONS:
|
||||||
|
{{range .Flags}}{{.}}
|
||||||
|
{{end}}
|
||||||
|
`
|
||||||
|
|
||||||
|
cli.HelpPrinter = func(templ string, data interface{}) {
|
||||||
|
w := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', 0)
|
||||||
|
t := template.Must(template.New("help").Parse(templ))
|
||||||
|
err := t.Execute(w, data)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
w.Flush()
|
||||||
|
os.Exit(2)
|
||||||
|
}
|
||||||
|
|
||||||
|
app := cli.NewApp()
|
||||||
|
app.HideVersion = true
|
||||||
|
app.Usage = "a go micro app"
|
||||||
|
app.Action = func(c *cli.Context) {}
|
||||||
|
app.Before = Setup
|
||||||
|
app.Flags = Flags
|
||||||
|
app.RunAndExitOnError()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user