Skip to content

Commit

Permalink
add client debug flag
Browse files Browse the repository at this point in the history
add client debug flag, so we can get more debug info when running
pouch commands

Signed-off-by: Chuanyun Li <[email protected]>
  • Loading branch information
shaloulcy committed Apr 27, 2018
1 parent 98ec8f3 commit 98bb574
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ var pouchDescription = "pouch is a client side tool pouch to interact with daemo

// Option uses to define the global options.
type Option struct {
host string
TLS client.TLSConfig
host string
Debug bool
TLS client.TLSConfig
}

// Cli is the client's core struct, it will be used to manage all subcommand, send http request
Expand Down Expand Up @@ -51,6 +52,7 @@ func NewCli() *Cli {
func (c *Cli) SetFlags() *Cli {
flags := c.rootCmd.PersistentFlags()
flags.StringVarP(&c.Option.host, "host", "H", "unix:///var/run/pouchd.sock", "Specify connecting address of Pouch CLI")
flags.BoolVarP(&c.Option.Debug, "debug", "D", false, "Switch client log level to DEBUG mode")
flags.StringVar(&c.Option.TLS.Key, "tlskey", "", "Specify key file of TLS")
flags.StringVar(&c.Option.TLS.Cert, "tlscert", "", "Specify cert file of TLS")
flags.StringVar(&c.Option.TLS.CA, "tlscacert", "", "Specify CA file of TLS")
Expand All @@ -68,6 +70,21 @@ func (c *Cli) NewAPIClient() {
c.APIClient = client
}

// InitLog initializes log Level and log format of client.
func (c *Cli) InitLog() {
if c.Option.Debug {
logrus.SetLevel(logrus.DebugLevel)
logrus.Infof("start client at debug level")
}

formatter := &logrus.TextFormatter{
ForceColors: true,
FullTimestamp: true,
TimestampFormat: "2006-01-02 15:04:05.000000000",
}
logrus.SetFormatter(formatter)
}

// Client returns API client torwards daemon.
func (c *Cli) Client() client.CommonAPIClient {
return c.APIClient
Expand All @@ -92,6 +109,7 @@ func (c *Cli) AddCommand(parent, child Command) {

childCmd.PreRun = func(cmd *cobra.Command, args []string) {
c.NewAPIClient()
c.InitLog()
}

parentCmd.AddCommand(childCmd)
Expand Down

0 comments on commit 98bb574

Please sign in to comment.