From 3fdf2b3b418108eb22ba74f1a7493284c4044524 Mon Sep 17 00:00:00 2001 From: Zachary Scott Date: Wed, 6 Jun 2018 21:03:07 +0900 Subject: [PATCH] client.Client.Run should print it's message to debug Also added logger.Logger.Infoln that wraps log.Logger.Println --- client/client.go | 2 +- cmd/diagnostic.go | 7 ++++--- cmd/query.go | 3 +-- cmd/root.go | 10 ++-------- logger/logger.go | 6 ++++++ 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/client/client.go b/client/client.go index 79adb65b3..299140a82 100644 --- a/client/client.go +++ b/client/client.go @@ -37,7 +37,7 @@ func (c *Client) Run(query string) (map[string]interface{}, error) { ctx := context.Background() var resp map[string]interface{} - c.logger.Info("Querying ", c.endpoint, " with:\n\n", query, "\n\n") + c.logger.Debug("Querying %s with:\n\n%s\n\n", c.endpoint, query) err := c.client.Run(ctx, req, &resp) return resp, err } diff --git a/cmd/diagnostic.go b/cmd/diagnostic.go index dc974371e..bfb0c1437 100644 --- a/cmd/diagnostic.go +++ b/cmd/diagnostic.go @@ -15,14 +15,15 @@ func diagnostic(cmd *cobra.Command, args []string) { endpoint := viper.GetString("endpoint") token := viper.GetString("token") - Logger.Info("\n---\nCircleCI CLI Diagnostics\n---\n\n") + Logger.Infoln("\n---\nCircleCI CLI Diagnostics\n---\n") Logger.Infof("Config found: `%v`\n", viper.ConfigFileUsed()) Logger.Infof("GraphQL API endpoint: %s\n", endpoint) if token == "token" || token == "" { - Logger.Info("Please set a token!") + var err error + Logger.FatalOnError("Please set a token!", err) } else { - Logger.Info("OK, got a token.") + Logger.Infoln("OK, got a token.") } } diff --git a/cmd/query.go b/cmd/query.go index d66ba0c28..345c2e411 100644 --- a/cmd/query.go +++ b/cmd/query.go @@ -27,6 +27,5 @@ func query(cmd *cobra.Command, args []string) { b, err := json.MarshalIndent(resp, "", " ") Logger.FatalOnError("Could not parse graphql response", err) - Logger.Info("Result: \n\n") - Logger.Info(string(b) + "\n") + Logger.Infoln(string(b)) } diff --git a/cmd/root.go b/cmd/root.go index de9a624cc..543d8b4f9 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -123,16 +123,10 @@ func createConfig() (err error) { endpoint := viper.GetString("endpoint") token := viper.GetString("token") - if endpoint == "endpoint" || endpoint == "" { - Logger.Info("Please enter the HTTP(S) endpoint to your CircleCI GraphQL API:") - fmt.Scanln(&endpoint) - Logger.Info("OK.\n") - } - if token == "token" || token == "" { Logger.Info("Please enter your CircleCI API token: ") fmt.Scanln(&token) - Logger.Info("OK.\n") + Logger.Infoln("OK.") } // format input @@ -144,6 +138,6 @@ func createConfig() (err error) { } Logger.Info("Your configuration has been created in `%v`.\n", cfgPathDefault) - Logger.Info("It can edited manually for advanced settings.\n") + Logger.Infoln("It can edited manually for advanced settings.") return err } diff --git a/logger/logger.go b/logger/logger.go index 6304960ef..f46910999 100644 --- a/logger/logger.go +++ b/logger/logger.go @@ -43,6 +43,12 @@ func (l *Logger) Info(args ...interface{}) { l.info.Print(args...) } +// Infoln prints all args to os.Stdout followed by a newline. +// This method wraps log.Logger.Println +func (l *Logger) Infoln(args ...interface{}) { + l.info.Println(args...) +} + // Infof prints a formatted message to stdout // This method wraps log.Logger.Printf func (l *Logger) Infof(format string, args ...interface{}) {