Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jiraExec Template Function #412

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions jiracli/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@ import (
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"reflect"
"regexp"
"strconv"
"strings"
"text/template"

yaml "gopkg.in/coryb/yaml.v2"
"golang.org/x/crypto/ssh/terminal"

"github.com/Masterminds/sprig"
"github.com/coryb/figtree"
shellquote "github.com/kballard/go-shellquote"
"github.com/mgutz/ansi"
"github.com/olekukonko/tablewriter"
wordwrap "github.com/mitchellh/go-wordwrap"
"golang.org/x/crypto/ssh/terminal"
"github.com/olekukonko/tablewriter"
yaml "gopkg.in/coryb/yaml.v2"
)

func findTemplate(name string) ([]byte, error) {
Expand Down Expand Up @@ -71,6 +72,25 @@ func TemplateProcessor() *template.Template {
"jira": func() string {
return os.Args[0]
},
"jiraExec": func(stdin interface{}, args ...interface{}) *exec.Cmd {
var outb, errb bytes.Buffer
var argStrings = make([]string, len(args))
for i, d := range args {
argStrings[i] = fmt.Sprint(d)
}
cmd := exec.Command(os.Args[0], argStrings...)
if stdinStr := fmt.Sprint(stdin); stdinStr != "" {
cmd.Stdin = strings.NewReader(stdinStr)
}
cmd.Stdout = &outb
cmd.Stderr = &errb
err := cmd.Run()
if err != nil {
log.Warning("error running %v: %v", cmd.Args, err)
log.Warning("error: %v", cmd.Stderr)
}
return cmd
},
"env": func() map[string]string {
out := map[string]string{}
for _, env := range os.Environ() {
Expand Down