Use Run instead of Init for cmd

This commit is contained in:
Asim Aslam 2020-07-19 18:14:18 +01:00
parent 7aa92fa8b5
commit 755b816086

View File

@ -6,6 +6,7 @@ import (
"crypto/x509" "crypto/x509"
"io/ioutil" "io/ioutil"
"math/rand" "math/rand"
"os"
"strings" "strings"
"time" "time"
@ -87,13 +88,15 @@ import (
) )
type Cmd interface { type Cmd interface {
// Init parses the command line args // Init initialises options
// TODO: replace with Run method // Note: Use Run to parse command line
Init(opts ...Option) error Init(opts ...Option) error
// The cli app within this cmd
App() *cli.App
// Options set within this command // Options set within this command
Options() Options Options() Options
// The cli app within this cmd
App() *cli.App
// Run executes the command
Run() error
// Implementation // Implementation
String() string String() string
} }
@ -900,10 +903,13 @@ func (c *cmd) Init(opts ...Option) error {
} }
c.app.HideVersion = len(c.opts.Version) == 0 c.app.HideVersion = len(c.opts.Version) == 0
c.app.Usage = c.opts.Description c.app.Usage = c.opts.Description
c.app.RunAndExitOnError()
return nil return nil
} }
func (c *cmd) Run() error {
return c.app.Run(os.Args)
}
func (c *cmd) String() string { func (c *cmd) String() string {
return "micro/cli" return "micro/cli"
} }