Allow reading password from stdin

Allow reading password from stdin in `jira login`. This is useful for
combining the jira tool with other command-line utilities.
This commit is contained in:
Justin Ko
2019-06-05 14:08:09 -07:00
parent f1390760b4
commit 225e1dcc05
2 changed files with 16 additions and 1 deletions
+7
View File
@@ -3,6 +3,7 @@ package jiracli
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"os/exec"
"strings"
@@ -57,6 +58,12 @@ func (o *GlobalOptions) GetPass() string {
passwd = strings.TrimSpace(buf.String())
}
}
} else if o.PasswordSource.Value == "stdin" {
allBytes, err := ioutil.ReadAll(os.Stdin)
if err != nil {
panic(fmt.Sprintf("unable to read bytes from stdin: %s", err))
}
passwd = string(allBytes)
} else {
log.Warningf("Unknown password-source: %s", o.PasswordSource)
}