Skip to content

Commit

Permalink
change for api changes to go-logging
Browse files Browse the repository at this point in the history
  • Loading branch information
coryb committed Feb 11, 2016
1 parent 7ef8c4f commit 7bfc6e8
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 125 deletions.
42 changes: 21 additions & 21 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"encoding/json"
"fmt"
"github.com/kballard/go-shellquote"
"github.com/op/go-logging"
"gopkg.in/coryb/yaml.v2"
"gopkg.in/op/go-logging.v1"
"io/ioutil"
"net/http"
"net/http/cookiejar"
Expand Down Expand Up @@ -100,15 +100,15 @@ func (c *Cli) loadCookies() []*http.Cookie {
return nil
}
if err != nil {
log.Error("Failed to open %s: %s", c.cookieFile, err)
log.Errorf("Failed to open %s: %s", c.cookieFile, err)
os.Exit(1)
}
cookies := make([]*http.Cookie, 0)
err = json.Unmarshal(bytes, &cookies)
if err != nil {
log.Error("Failed to parse json from file %s: %s", c.cookieFile, err)
log.Errorf("Failed to parse json from file %s: %s", c.cookieFile, err)
}
log.Debug("Loading Cookies: %s", cookies)
log.Debugf("Loading Cookies: %s", cookies)
return cookies
}

Expand All @@ -123,7 +123,7 @@ func (c *Cli) put(uri string, content string) (*http.Response, error) {
func (c *Cli) delete(uri string) (*http.Response, error) {
method := "DELETE"
req, _ := http.NewRequest(method, uri, nil)
log.Info("%s %s", req.Method, req.URL.String())
log.Infof("%s %s", req.Method, req.URL.String())
if resp, err := c.makeRequest(req); err != nil {
return nil, err
} else {
Expand All @@ -142,11 +142,11 @@ func (c *Cli) makeRequestWithContent(method string, uri string, content string)
buffer := bytes.NewBufferString(content)
req, _ := http.NewRequest(method, uri, buffer)

log.Info("%s %s", req.Method, req.URL.String())
log.Infof("%s %s", req.Method, req.URL.String())
if log.IsEnabledFor(logging.DEBUG) {
logBuffer := bytes.NewBuffer(make([]byte, 0, len(content)))
req.Write(logBuffer)
log.Debug("%s", logBuffer)
log.Debugf("%s", logBuffer)
// need to recreate the buffer since the offset is now at the end
// need to be able to rewind the buffer offset, dont know how yet
req, _ = http.NewRequest(method, uri, bytes.NewBufferString(content))
Expand All @@ -168,11 +168,11 @@ func (c *Cli) makeRequestWithContent(method string, uri string, content string)

func (c *Cli) get(uri string) (*http.Response, error) {
req, _ := http.NewRequest("GET", uri, nil)
log.Info("%s %s", req.Method, req.URL.String())
log.Infof("%s %s", req.Method, req.URL.String())
if log.IsEnabledFor(logging.DEBUG) {
logBuffer := bytes.NewBuffer(make([]byte, 0))
req.Write(logBuffer)
log.Debug("%s", logBuffer)
log.Debugf("%s", logBuffer)
}

if resp, err := c.makeRequest(req); err != nil {
Expand All @@ -191,11 +191,11 @@ func (c *Cli) get(uri string) (*http.Response, error) {
func (c *Cli) makeRequest(req *http.Request) (resp *http.Response, err error) {
req.Header.Set("Content-Type", "application/json")
if resp, err = c.ua.Do(req); err != nil {
log.Error("Failed to %s %s: %s", req.Method, req.URL.String(), err)
log.Errorf("Failed to %s %s: %s", req.Method, req.URL.String(), err)
return nil, err
} else {
if resp.StatusCode < 200 || resp.StatusCode >= 300 && resp.StatusCode != 401 {
log.Error("response status: %s", resp.Status)
log.Errorf("response status: %s", resp.Status)
}

runtime.SetFinalizer(resp, func(r *http.Response) {
Expand Down Expand Up @@ -257,14 +257,14 @@ func (c *Cli) editTemplate(template string, tmpFilePrefix string, templateData m

fh, err := ioutil.TempFile(tmpdir, tmpFilePrefix)
if err != nil {
log.Error("Failed to make temp file in %s: %s", tmpdir, err)
log.Errorf("Failed to make temp file in %s: %s", tmpdir, err)
return err
}
defer fh.Close()

tmpFileName := fmt.Sprintf("%s.yml", fh.Name())
if err := os.Rename(fh.Name(), tmpFileName); err != nil {
log.Error("Failed to rename %s to %s: %s", fh.Name(), fmt.Sprintf("%s.yml", fh.Name()), err)
log.Errorf("Failed to rename %s to %s: %s", fh.Name(), fmt.Sprintf("%s.yml", fh.Name()), err)
return err
}
defer func() {
Expand Down Expand Up @@ -301,11 +301,11 @@ func (c *Cli) editTemplate(template string, tmpFilePrefix string, templateData m
if editing {
shell, _ := shellquote.Split(editor)
shell = append(shell, tmpFileName)
log.Debug("Running: %#v", shell)
log.Debugf("Running: %#v", shell)
cmd := exec.Command(shell[0], shell[1:]...)
cmd.Stdout, cmd.Stderr, cmd.Stdin = os.Stdout, os.Stderr, os.Stdin
if err := cmd.Run(); err != nil {
log.Error("Failed to edit template with %s: %s", editor, err)
log.Errorf("Failed to edit template with %s: %s", editor, err)
if promptYN("edit again?", true) {
continue
}
Expand All @@ -321,14 +321,14 @@ func (c *Cli) editTemplate(template string, tmpFilePrefix string, templateData m

edited := make(map[string]interface{})
if fh, err := ioutil.ReadFile(tmpFileName); err != nil {
log.Error("Failed to read tmpfile %s: %s", tmpFileName, err)
log.Errorf("Failed to read tmpfile %s: %s", tmpFileName, err)
if editing && promptYN("edit again?", true) {
continue
}
return err
} else {
if err := yaml.Unmarshal(fh, &edited); err != nil {
log.Error("Failed to parse YAML: %s", err)
log.Errorf("Failed to parse YAML: %s", err)
if editing && promptYN("edit again?", true) {
continue
}
Expand All @@ -346,7 +346,7 @@ func (c *Cli) editTemplate(template string, tmpFilePrefix string, templateData m
// you can add the "abort: true" flag to the document
// and we will abort now
if val, ok := edited["abort"].(bool); ok && val {
log.Info("abort flag found in template, quiting")
log.Infof("abort flag found in template, quiting")
return fmt.Errorf("abort flag found in template, quiting")
}

Expand All @@ -356,7 +356,7 @@ func (c *Cli) editTemplate(template string, tmpFilePrefix string, templateData m
for k := range f {
if _, ok := mf.(map[string]interface{})[k]; !ok {
err := fmt.Errorf("Field %s is not editable", k)
log.Error("%s", err)
log.Errorf("%s", err)
if editing && promptYN("edit again?", true) {
continue
}
Expand All @@ -372,7 +372,7 @@ func (c *Cli) editTemplate(template string, tmpFilePrefix string, templateData m
}

if err := templateProcessor(json); err != nil {
log.Error("%s", err)
log.Errorf("%s", err)
if editing && promptYN("edit again?", true) {
continue
}
Expand Down Expand Up @@ -418,7 +418,7 @@ func (c *Cli) FindIssues() (interface{}, error) {
qbuff := bytes.NewBufferString("resolution = unresolved")
if project, ok := c.opts["project"]; !ok {
err := fmt.Errorf("Missing required arguments, either 'query' or 'project' are required")
log.Error("%s", err)
log.Errorf("%s", err)
return nil, err
} else {
qbuff.WriteString(fmt.Sprintf(" AND project = '%s'", project))
Expand Down
Loading

0 comments on commit 7bfc6e8

Please sign in to comment.