aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/posener/complete/cmd/install/utils.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/posener/complete/cmd/install/utils.go')
-rw-r--r--vendor/github.com/posener/complete/cmd/install/utils.go24
1 files changed, 23 insertions, 1 deletions
diff --git a/vendor/github.com/posener/complete/cmd/install/utils.go b/vendor/github.com/posener/complete/cmd/install/utils.go
index 2c8b44c..d34ac8c 100644
--- a/vendor/github.com/posener/complete/cmd/install/utils.go
+++ b/vendor/github.com/posener/complete/cmd/install/utils.go
@@ -6,6 +6,7 @@ import (
6 "io" 6 "io"
7 "io/ioutil" 7 "io/ioutil"
8 "os" 8 "os"
9 "path/filepath"
9) 10)
10 11
11func lineInFile(name string, lookFor string) bool { 12func lineInFile(name string, lookFor string) bool {
@@ -36,6 +37,24 @@ func lineInFile(name string, lookFor string) bool {
36 } 37 }
37} 38}
38 39
40func createFile(name string, content string) error {
41 // make sure file directory exists
42 if err := os.MkdirAll(filepath.Dir(name), 0775); err != nil {
43 return err
44 }
45
46 // create the file
47 f, err := os.Create(name)
48 if err != nil {
49 return err
50 }
51 defer f.Close()
52
53 // write file content
54 _, err = f.WriteString(fmt.Sprintf("%s\n", content))
55 return err
56}
57
39func appendToFile(name string, content string) error { 58func appendToFile(name string, content string) error {
40 f, err := os.OpenFile(name, os.O_RDWR|os.O_APPEND, 0) 59 f, err := os.OpenFile(name, os.O_RDWR|os.O_APPEND, 0)
41 if err != nil { 60 if err != nil {
@@ -96,7 +115,10 @@ func removeContentToTempFile(name, content string) (string, error) {
96 if str == content { 115 if str == content {
97 continue 116 continue
98 } 117 }
99 wf.WriteString(str + "\n") 118 _, err = wf.WriteString(str + "\n")
119 if err != nil {
120 return "", err
121 }
100 prefix = prefix[:0] 122 prefix = prefix[:0]
101 } 123 }
102 return wf.Name(), nil 124 return wf.Name(), nil