Update help printer

This commit is contained in:
Asim 2016-01-01 02:45:15 +00:00
parent 9e7e8742b4
commit 59a667130c
3 changed files with 28 additions and 1 deletions

View File

@ -3,6 +3,7 @@ package cmd
import ( import (
"flag" "flag"
"fmt" "fmt"
"io"
"math/rand" "math/rand"
"os" "os"
"strings" "strings"
@ -160,6 +161,11 @@ var (
func init() { func init() {
rand.Seed(time.Now().Unix()) rand.Seed(time.Now().Unix())
help := cli.HelpPrinter
cli.HelpPrinter = func(writer io.Writer, templ string, data interface{}) {
help(writer, templ, data)
os.Exit(0)
}
} }
func newCmd(opts ...Option) Cmd { func newCmd(opts ...Option) Cmd {
@ -174,6 +180,10 @@ func newCmd(opts ...Option) Cmd {
o(&options) o(&options)
} }
if len(options.Description) == 0 {
options.Description = "a go-micro service"
}
cmd := new(cmd) cmd := new(cmd)
cmd.opts = options cmd.opts = options
cmd.app = cli.NewApp() cmd.app = cli.NewApp()
@ -183,6 +193,11 @@ func newCmd(opts ...Option) Cmd {
cmd.app.Before = cmd.Before cmd.app.Before = cmd.Before
cmd.app.Flags = DefaultFlags cmd.app.Flags = DefaultFlags
cmd.app.Action = func(c *cli.Context) {} cmd.app.Action = func(c *cli.Context) {}
if len(options.Version) == 0 {
cmd.app.HideVersion = true
}
return cmd return cmd
} }

View File

@ -28,7 +28,6 @@ type Options struct {
func newOptions(opts ...Option) Options { func newOptions(opts ...Option) Options {
opt := Options{ opt := Options{
Broker: broker.DefaultBroker, Broker: broker.DefaultBroker,
Cmd: cmd.DefaultCmd,
Client: client.DefaultClient, Client: client.DefaultClient,
Server: server.DefaultServer, Server: server.DefaultServer,
Registry: registry.DefaultRegistry, Registry: registry.DefaultRegistry,
@ -40,6 +39,14 @@ func newOptions(opts ...Option) Options {
o(&opt) o(&opt)
} }
// New Command
if opt.Cmd == nil {
opt.Cmd = cmd.NewCmd(
cmd.Name(opt.Server.Options().Name),
cmd.Version(opt.Server.Options().Version),
)
}
return opt return opt
} }

View File

@ -32,6 +32,11 @@ func newService(opts ...Option) Service {
func (s *service) Init(opts ...Option) { func (s *service) Init(opts ...Option) {
s.opts.Cmd.Init() s.opts.Cmd.Init()
for _, o := range opts {
o(&s.opts)
}
s = newService(opts...).(*service) s = newService(opts...).(*service)
} }