aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2017-06-03 21:39:38 +0200
committerTeddy Wing2017-06-03 21:39:38 +0200
commit8c0f7e4c10643f3519c5900497dcf2ef326b178d (patch)
tree58b43be49d3e470d68543ced658c22c9ea07bf9b
parent3062c5a1923c0021f6e29e9ab3fe2e7184c7be35 (diff)
parentf5b1fb3d0ef37ed44b8f7302343dcd5cd16bd725 (diff)
downloadtimetasker-8c0f7e4c10643f3519c5900497dcf2ef326b178d.tar.bz2
Merge branch 'password-cmd' into timetasker-daily
-rw-r--r--main.go7
-rw-r--r--password_cmd.go22
2 files changed, 27 insertions, 2 deletions
diff --git a/main.go b/main.go
index 882efde..ab0fc4a 100644
--- a/main.go
+++ b/main.go
@@ -39,7 +39,7 @@ func main() {
description := kingpin.Flag("description", "Description of work.").
Short('m').
String()
- write_config_description := fmt.Sprintf(
+ write_config_description := fmt.Sprintf(
"Initialise a new config file template at %s",
configFile(),
)
@@ -87,9 +87,12 @@ func main() {
*description,
)
+ password, err := passwordCmd(config.Auth.PasswordCmd)
+ kingpin.FatalIfError(err, "password command failed")
+
resp, client, err := timetask.Login(
config.Auth.Username,
- config.Auth.PasswordCmd,
+ password,
)
kingpin.FatalIfError(err, "Login request failed")
log.Printf("%+v\n", resp)
diff --git a/password_cmd.go b/password_cmd.go
new file mode 100644
index 0000000..821c8f6
--- /dev/null
+++ b/password_cmd.go
@@ -0,0 +1,22 @@
+package main
+
+import (
+ "os"
+ "os/exec"
+)
+
+// Execute the given string as a shell command and return the resulting output
+func passwordCmd(password_cmd string) (password string, err error) {
+ shell := os.Getenv("SHELL")
+
+ // `Command` requires us to pass shell arguments as parameters to the
+ // function, but we don't know what the arguments are because
+ // `password_cmd` is an arbitrary command. To get around this, we pass the
+ // password command to the current shell to execute.
+ output, err := exec.Command(shell, "-c", password_cmd).Output()
+ if err != nil {
+ return "", err
+ }
+
+ return string(output), nil
+}