Skip to content

Commit

Permalink
Make lint happy
Browse files Browse the repository at this point in the history
Will come back to address the complexity of (*Config).create()
  • Loading branch information
Zachary Scott committed Jun 12, 2018
1 parent 9d95527 commit 941ee94
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
3 changes: 3 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ func (c *Client) Run(query string) (string, error) {

c.logger.Debug("Querying %s with:\n\n%s\n\n", c.endpoint, query)
err := c.client.Run(ctx, req, &resp)
if err != nil {
return "", err
}

b, err := json.MarshalIndent(resp, "", " ")
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ func query(cmd *cobra.Command, args []string) {
Logger.FatalOnError("Error occurred when running query", err)
}

Logger.Infoln(string(resp))
Logger.Infoln(resp)
}
21 changes: 12 additions & 9 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package config

import (
"errors"
"fmt"
"os"

"github.com/spf13/viper"
)

// Config is a struct of the current configuration available at runtime.
type Config struct {
Verbose bool
File string
Expand All @@ -30,10 +30,8 @@ func (c *Config) Init() error {
c.File = c.DefaultPath

// reload after creating config
if err := c.read(); err != nil {
return err
}
return nil
err := c.read()
return err
}

// read tries to load the config either from Config.defaultPath or Config.file.
Expand Down Expand Up @@ -68,10 +66,10 @@ func (c *Config) create() error {

if _, err := os.Stat(path); os.IsNotExist(err) {
if err = os.Mkdir(path, 0700); err != nil {
return errors.New(fmt.Sprintf("Error creating directory: '%s'", path))
return fmt.Errorf("Error creating directory: '%s'", path)
}
} else {
return errors.New(fmt.Sprintf("Error accessing directory: '%s'", path))
return fmt.Errorf("Error accessing directory: '%s'", path)
}

// Create default config file
Expand All @@ -85,7 +83,10 @@ func (c *Config) create() error {
return err
}
defer func() {
file.Close()
cerr := file.Close()
if err == nil {
err = cerr
}
}()

// read flag values
Expand All @@ -94,7 +95,9 @@ func (c *Config) create() error {

if token == "token" || token == "" {
fmt.Print("Please enter your CircleCI API token: ")
fmt.Scanln(&token)
if _, err = fmt.Scanln(&token); err != nil {
return err
}
fmt.Println("OK.")
}

Expand Down

0 comments on commit 941ee94

Please sign in to comment.