mirror of
https://github.com/Threnklyn/jira.git
synced 2026-06-07 13:33:32 +02:00
add --quiet command to not print the OK ..
add --saveFile option to print the issue/link to a file on create command
This commit is contained in:
@@ -354,6 +354,13 @@ func (c *Cli) Browse(issue string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Cli) SaveData(data interface{}) error {
|
||||||
|
if val, ok := c.opts["saveFile"].(string); ok && val != "" {
|
||||||
|
yamlWrite(val, data)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Cli) FindIssues() (interface{}, error) {
|
func (c *Cli) FindIssues() (interface{}, error) {
|
||||||
var query string
|
var query string
|
||||||
var ok bool
|
var ok bool
|
||||||
|
|||||||
+31
-11
@@ -126,7 +126,9 @@ func (c *Cli) CmdEdit(issue string) error {
|
|||||||
|
|
||||||
if resp.StatusCode == 204 {
|
if resp.StatusCode == 204 {
|
||||||
c.Browse(issueData["key"].(string))
|
c.Browse(issueData["key"].(string))
|
||||||
fmt.Printf("OK %s %s/browse/%s\n", issueData["key"], c.endpoint, issueData["key"])
|
if ! c.opts["quiet"].(bool) {
|
||||||
|
fmt.Printf("OK %s %s/browse/%s\n", issueData["key"], c.endpoint, issueData["key"])
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
} else {
|
} else {
|
||||||
logBuffer := bytes.NewBuffer(make([]byte, 0))
|
logBuffer := bytes.NewBuffer(make([]byte, 0))
|
||||||
@@ -260,10 +262,16 @@ func (c *Cli) CmdCreate() error {
|
|||||||
if json, err := responseToJson(resp, nil); err != nil {
|
if json, err := responseToJson(resp, nil); err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
key := json.(map[string]interface{})["key"]
|
key := json.(map[string]interface{})["key"].(string)
|
||||||
c.Browse(key.(string))
|
link := fmt.Sprintf("%s/browse/%s", c.endpoint, key)
|
||||||
fmt.Printf("OK %s %s/browse/%s\n", key, c.endpoint, key)
|
c.Browse(key)
|
||||||
|
c.SaveData(map[string]string{
|
||||||
|
"issue": key,
|
||||||
|
"link": link,
|
||||||
|
})
|
||||||
|
if ! c.opts["quiet"].(bool) {
|
||||||
|
fmt.Printf("OK %s %s\n", key, link)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
} else {
|
} else {
|
||||||
@@ -318,7 +326,9 @@ func (c *Cli) CmdBlocks(blocker string, issue string) error {
|
|||||||
}
|
}
|
||||||
if resp.StatusCode == 201 {
|
if resp.StatusCode == 201 {
|
||||||
c.Browse(issue)
|
c.Browse(issue)
|
||||||
fmt.Printf("OK %s %s/browse/%s\n", issue, c.endpoint, issue)
|
if ! c.opts["quiet"].(bool) {
|
||||||
|
fmt.Printf("OK %s %s/browse/%s\n", issue, c.endpoint, issue)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
logBuffer := bytes.NewBuffer(make([]byte, 0))
|
logBuffer := bytes.NewBuffer(make([]byte, 0))
|
||||||
resp.Write(logBuffer)
|
resp.Write(logBuffer)
|
||||||
@@ -359,7 +369,9 @@ func (c *Cli) CmdDups(duplicate string, issue string) error {
|
|||||||
}
|
}
|
||||||
if resp.StatusCode == 201 {
|
if resp.StatusCode == 201 {
|
||||||
c.Browse(issue)
|
c.Browse(issue)
|
||||||
fmt.Printf("OK %s %s/browse/%s\n", issue, c.endpoint, issue)
|
if ! c.opts["quiet"].(bool) {
|
||||||
|
fmt.Printf("OK %s %s/browse/%s\n", issue, c.endpoint, issue)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
logBuffer := bytes.NewBuffer(make([]byte, 0))
|
logBuffer := bytes.NewBuffer(make([]byte, 0))
|
||||||
resp.Write(logBuffer)
|
resp.Write(logBuffer)
|
||||||
@@ -391,7 +403,9 @@ func (c *Cli) CmdWatch(issue string) error {
|
|||||||
}
|
}
|
||||||
if resp.StatusCode == 204 {
|
if resp.StatusCode == 204 {
|
||||||
c.Browse(issue)
|
c.Browse(issue)
|
||||||
fmt.Printf("OK %s %s/browse/%s\n", issue, c.endpoint, issue)
|
if ! c.opts["quiet"].(bool) {
|
||||||
|
fmt.Printf("OK %s %s/browse/%s\n", issue, c.endpoint, issue)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
logBuffer := bytes.NewBuffer(make([]byte, 0))
|
logBuffer := bytes.NewBuffer(make([]byte, 0))
|
||||||
resp.Write(logBuffer)
|
resp.Write(logBuffer)
|
||||||
@@ -445,7 +459,9 @@ func (c *Cli) CmdTransition(issue string, trans string) error {
|
|||||||
}
|
}
|
||||||
if resp.StatusCode == 204 {
|
if resp.StatusCode == 204 {
|
||||||
c.Browse(issue)
|
c.Browse(issue)
|
||||||
fmt.Printf("OK %s %s/browse/%s\n", issue, c.endpoint, issue)
|
if ! c.opts["quiet"].(bool) {
|
||||||
|
fmt.Printf("OK %s %s/browse/%s\n", issue, c.endpoint, issue)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
logBuffer := bytes.NewBuffer(make([]byte, 0))
|
logBuffer := bytes.NewBuffer(make([]byte, 0))
|
||||||
resp.Write(logBuffer)
|
resp.Write(logBuffer)
|
||||||
@@ -496,7 +512,9 @@ func (c *Cli) CmdComment(issue string) error {
|
|||||||
|
|
||||||
if resp.StatusCode == 201 {
|
if resp.StatusCode == 201 {
|
||||||
c.Browse(issue)
|
c.Browse(issue)
|
||||||
fmt.Printf("OK %s %s/browse/%s\n", issue, c.endpoint, issue)
|
if ! c.opts["quiet"].(bool) {
|
||||||
|
fmt.Printf("OK %s %s/browse/%s\n", issue, c.endpoint, issue)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
} else {
|
} else {
|
||||||
logBuffer := bytes.NewBuffer(make([]byte, 0))
|
logBuffer := bytes.NewBuffer(make([]byte, 0))
|
||||||
@@ -548,7 +566,9 @@ func (c *Cli) CmdAssign(issue string, user string) error {
|
|||||||
}
|
}
|
||||||
if resp.StatusCode == 204 {
|
if resp.StatusCode == 204 {
|
||||||
c.Browse(issue)
|
c.Browse(issue)
|
||||||
fmt.Printf("OK %s %s/browse/%s\n", issue, c.endpoint, issue)
|
if ! c.opts["quiet"].(bool) {
|
||||||
|
fmt.Printf("OK %s %s/browse/%s\n", issue, c.endpoint, issue)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
logBuffer := bytes.NewBuffer(make([]byte, 0))
|
logBuffer := bytes.NewBuffer(make([]byte, 0))
|
||||||
resp.Write(logBuffer)
|
resp.Write(logBuffer)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"gopkg.in/coryb/yaml.v2"
|
||||||
"github.com/mgutz/ansi"
|
"github.com/mgutz/ansi"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@@ -245,6 +246,21 @@ func jsonWrite(file string, data interface{}) {
|
|||||||
enc.Encode(data)
|
enc.Encode(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func yamlWrite(file string, data interface{}) {
|
||||||
|
fh, err := os.OpenFile(file, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
|
||||||
|
defer fh.Close()
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Failed to open %s: %s", file, err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
if out, err := yaml.Marshal(data); err != nil {
|
||||||
|
log.Error("Failed to marshal yaml %v: %s", data, err)
|
||||||
|
os.Exit(1)
|
||||||
|
} else {
|
||||||
|
fh.Write(out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func promptYN(prompt string, yes bool) bool {
|
func promptYN(prompt string, yes bool) bool {
|
||||||
reader := bufio.NewReader(os.Stdin)
|
reader := bufio.NewReader(os.Stdin)
|
||||||
if !yes {
|
if !yes {
|
||||||
|
|||||||
@@ -199,6 +199,8 @@ Command Options:
|
|||||||
"m|comment=s": setopt,
|
"m|comment=s": setopt,
|
||||||
"d|dir|directory=s": setopt,
|
"d|dir|directory=s": setopt,
|
||||||
"M|method=s": setopt,
|
"M|method=s": setopt,
|
||||||
|
"S|saveFile=s": setopt,
|
||||||
|
"Q|quiet": setopt,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err := op.ProcessAll(os.Args[1:]); err != nil {
|
if err := op.ProcessAll(os.Args[1:]); err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user