Skip to content

Commit

Permalink
Merge pull request #22 from mikepea/library_break_out
Browse files Browse the repository at this point in the history
Expose key functionality for library consumption
  • Loading branch information
coryb committed Dec 31, 2015
2 parents 425b571 + 8977f3d commit 8712b4a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
16 changes: 15 additions & 1 deletion cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
)

var (
log = logging.MustGetLogger("jira")
log = logging.MustGetLogger("jira")
VERSION string
)

Expand Down Expand Up @@ -177,6 +177,10 @@ func (c *Cli) makeRequest(req *http.Request) (resp *http.Response, err error) {
return resp, nil
}

func (c *Cli) GetTemplate(name string) string {
return c.getTemplate(name)
}

func (c *Cli) getTemplate(name string) string {
if override, ok := c.opts["template"].(string); ok {
if _, err := os.Stat(override); err == nil {
Expand Down Expand Up @@ -364,6 +368,16 @@ func (c *Cli) SaveData(data interface{}) error {
return nil
}

func (c *Cli) ViewIssue(issue string) (interface{}, error) {
uri := fmt.Sprintf("%s/rest/api/2/issue/%s", c.endpoint, issue)
data, err := responseToJson(c.get(uri))
if err != nil {
return nil, err
} else {
return data, nil
}
}

func (c *Cli) FindIssues() (interface{}, error) {
var query string
var ok bool
Expand Down
4 changes: 1 addition & 3 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,10 @@ func (c *Cli) CmdList() error {
func (c *Cli) CmdView(issue string) error {
log.Debug("view called")
c.Browse(issue)
uri := fmt.Sprintf("%s/rest/api/2/issue/%s", c.endpoint, issue)
data, err := responseToJson(c.get(uri))
data, err := c.ViewIssue(issue)
if err != nil {
return err
}

return runTemplate(c.getTemplate("view"), data, nil)
}

Expand Down
4 changes: 2 additions & 2 deletions main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
)

var (
log = logging.MustGetLogger("jira")
format = "%{color}%{time:2006-01-02T15:04:05.000Z07:00} %{level:-5s} [%{shortfile}]%{color:reset} %{message}"
log = logging.MustGetLogger("jira")
format = "%{color}%{time:2006-01-02T15:04:05.000Z07:00} %{level:-5s} [%{shortfile}]%{color:reset} %{message}"
)

func main() {
Expand Down
5 changes: 4 additions & 1 deletion util.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,11 @@ func dateFormat(format string, content string) (string, error) {
}
}

func runTemplate(templateContent string, data interface{}, out io.Writer) error {
func RunTemplate(templateContent string, data interface{}, out io.Writer) error {
return runTemplate(templateContent, data, out)
}

func runTemplate(templateContent string, data interface{}, out io.Writer) error {
if out == nil {
out = os.Stdout
}
Expand Down

0 comments on commit 8712b4a

Please sign in to comment.