mirror of
https://github.com/go-micro/go-micro.git
synced 2024-11-24 08:02:32 +02:00
Update help printer
This commit is contained in:
parent
9e7e8742b4
commit
59a667130c
15
cmd/cmd.go
15
cmd/cmd.go
@ -3,6 +3,7 @@ package cmd
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"math/rand"
|
||||
"os"
|
||||
"strings"
|
||||
@ -160,6 +161,11 @@ var (
|
||||
|
||||
func init() {
|
||||
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 {
|
||||
@ -174,6 +180,10 @@ func newCmd(opts ...Option) Cmd {
|
||||
o(&options)
|
||||
}
|
||||
|
||||
if len(options.Description) == 0 {
|
||||
options.Description = "a go-micro service"
|
||||
}
|
||||
|
||||
cmd := new(cmd)
|
||||
cmd.opts = options
|
||||
cmd.app = cli.NewApp()
|
||||
@ -183,6 +193,11 @@ func newCmd(opts ...Option) Cmd {
|
||||
cmd.app.Before = cmd.Before
|
||||
cmd.app.Flags = DefaultFlags
|
||||
cmd.app.Action = func(c *cli.Context) {}
|
||||
|
||||
if len(options.Version) == 0 {
|
||||
cmd.app.HideVersion = true
|
||||
}
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,6 @@ type Options struct {
|
||||
func newOptions(opts ...Option) Options {
|
||||
opt := Options{
|
||||
Broker: broker.DefaultBroker,
|
||||
Cmd: cmd.DefaultCmd,
|
||||
Client: client.DefaultClient,
|
||||
Server: server.DefaultServer,
|
||||
Registry: registry.DefaultRegistry,
|
||||
@ -40,6 +39,14 @@ func newOptions(opts ...Option) Options {
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,11 @@ func newService(opts ...Option) Service {
|
||||
|
||||
func (s *service) Init(opts ...Option) {
|
||||
s.opts.Cmd.Init()
|
||||
|
||||
for _, o := range opts {
|
||||
o(&s.opts)
|
||||
}
|
||||
|
||||
s = newService(opts...).(*service)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user