Update help printer
This commit is contained in:
		
							
								
								
									
										15
									
								
								cmd/cmd.go
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								cmd/cmd.go
									
									
									
									
									
								
							| @@ -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 | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -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 | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -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) | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user