Skip to content

Commit

Permalink
We can access the logger from config so no need to pass it around
Browse files Browse the repository at this point in the history
  • Loading branch information
Zachary Scott committed Jun 12, 2018
1 parent 84da9f9 commit 385c42e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
9 changes: 3 additions & 6 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package client
import (
"context"

"github.com/circleci/circleci-cli/logger"
"github.com/circleci/circleci-cli/config"
"github.com/machinebox/graphql"
)

Expand All @@ -12,18 +12,15 @@ type Client struct {
endpoint string
token string
client *graphql.Client
logger *logger.Logger
}

// NewClient returns a reference to a Client.
// We also call graphql.NewClient to initialize a new GraphQL Client.
// Then we pass the Logger originally constructed as cmd.Logger.
func NewClient(endpoint string, token string, logger *logger.Logger) *Client {
func NewClient(endpoint string, token string) *Client {
return &Client{
endpoint,
token,
graphql.NewClient(endpoint),
logger,
}
}

Expand All @@ -37,7 +34,7 @@ func (c *Client) Run(query string) (map[string]interface{}, error) {
ctx := context.Background()
var resp map[string]interface{}

c.logger.Debug("Querying %s with:\n\n%s\n\n", c.endpoint, query)
config.Logger.Debug("Querying %s with:\n\n%s\n\n", c.endpoint, query)
err := c.client.Run(ctx, req, &resp)
return resp, err
}
2 changes: 1 addition & 1 deletion cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var queryCmd = &cobra.Command{
}

func query(cmd *cobra.Command, args []string) {
client := client.NewClient(viper.GetString("endpoint"), viper.GetString("token"), config.Logger)
client := client.NewClient(viper.GetString("endpoint"), viper.GetString("token"))

query, err := ioutil.ReadAll(os.Stdin)
config.Logger.FatalOnError("Something happened", err)
Expand Down

0 comments on commit 385c42e

Please sign in to comment.