summaryrefslogtreecommitdiffstats
path: root/pkg/commands/os.go
diff options
context:
space:
mode:
authorMark Kopenga <mkopenga@gmail.com>2018-12-06 08:31:12 +0100
committerGitHub <noreply@github.com>2018-12-06 08:31:12 +0100
commit1b6d34e76a4d5d132f95072139fb3aba760eb771 (patch)
treefb6cc607a67f0d3d2ef0b9d66fafd439864e6d9a /pkg/commands/os.go
parent67115436347dec591d12a1a31d1c971915cf0b05 (diff)
parent1a6a69a8f1f7c44978a384ba56321149f973223d (diff)
Merge branch 'master' into https-ask-for-username-password
Diffstat (limited to 'pkg/commands/os.go')
-rw-r--r--pkg/commands/os.go28
1 files changed, 27 insertions, 1 deletions
diff --git a/pkg/commands/os.go b/pkg/commands/os.go
index f64f0732e..faf6c5aec 100644
--- a/pkg/commands/os.go
+++ b/pkg/commands/os.go
@@ -2,6 +2,7 @@ package commands
import (
"errors"
+ "io/ioutil"
"os"
"os/exec"
"regexp"
@@ -157,7 +158,7 @@ func (c *OSCommand) OpenFile(filename string) error {
return err
}
-// OpenFile opens a file with the given
+// OpenLink opens a file with the given
func (c *OSCommand) OpenLink(link string) error {
commandTemplate := c.Config.GetUserConfig().GetString("os.openLinkCommand")
templateValues := map[string]string{
@@ -224,3 +225,28 @@ func (c *OSCommand) AppendLineToFile(filename, line string) error {
_, err = f.WriteString("\n" + line)
return err
}
+
+// CreateTempFile writes a string to a new temp file and returns the file's name
+func (c *OSCommand) CreateTempFile(filename, content string) (string, error) {
+ tmpfile, err := ioutil.TempFile("", filename)
+ if err != nil {
+ c.Log.Error(err)
+ return "", err
+ }
+
+ if _, err := tmpfile.Write([]byte(content)); err != nil {
+ c.Log.Error(err)
+ return "", err
+ }
+ if err := tmpfile.Close(); err != nil {
+ c.Log.Error(err)
+ return "", err
+ }
+
+ return tmpfile.Name(), nil
+}
+
+// RemoveFile removes a file at the specified path
+func (c *OSCommand) RemoveFile(filename string) error {
+ return os.Remove(filename)
+}