5
5
"github.com/spf13/cobra"
6
6
"gopkg.in/yaml.v2"
7
7
"io/ioutil"
8
- "log"
9
8
"os"
10
9
"strconv"
11
10
"strings"
@@ -68,7 +67,7 @@ func readProperty(cmd *cobra.Command, args []string) {
68
67
69
68
func writeProperty (cmd * cobra.Command , args []string ) {
70
69
if len (args ) < 3 {
71
- log . Fatalf ("Must provide <filename> <path_to_update> <value>" )
70
+ die ("Must provide <filename> <path_to_update> <value>" )
72
71
}
73
72
74
73
var parsedData map [interface {}]interface {}
@@ -108,7 +107,7 @@ func printYaml(context interface{}) {
108
107
func yamlToString (context interface {}) string {
109
108
out , err := yaml .Marshal (context )
110
109
if err != nil {
111
- log . Fatalf ("error printing yaml: %v" , err )
110
+ die ("error printing yaml: %v" , err )
112
111
}
113
112
outStr := string (out )
114
113
// trim the trailing new line as it's easier for a script to add
@@ -121,7 +120,7 @@ func yamlToString(context interface{}) string {
121
120
122
121
func readYaml (args []string , parsedData * map [interface {}]interface {}) {
123
122
if len (args ) == 0 {
124
- log . Fatalf ("Must provide filename" )
123
+ die ("Must provide filename" )
125
124
}
126
125
127
126
var rawData []byte
@@ -133,22 +132,27 @@ func readYaml(args []string, parsedData *map[interface{}]interface{}) {
133
132
134
133
err := yaml .Unmarshal ([]byte (rawData ), & parsedData )
135
134
if err != nil {
136
- log . Fatalf ("error: %v" , err )
135
+ die ("error: %v" , err )
137
136
}
138
137
}
139
138
140
139
func readStdin () []byte {
141
140
bytes , err := ioutil .ReadAll (os .Stdin )
142
141
if err != nil {
143
- log . Fatalf ("error reading stdin" , err )
142
+ die ("error reading stdin" , err )
144
143
}
145
144
return bytes
146
145
}
147
146
148
147
func readFile (filename string ) []byte {
149
148
var rawData , readError = ioutil .ReadFile (filename )
150
149
if readError != nil {
151
- log . Fatalf ("error: %v" , readError )
150
+ die ("error: %v" , readError )
152
151
}
153
152
return rawData
154
153
}
154
+
155
+ func die (message ... interface {}) {
156
+ fmt .Println (message )
157
+ os .Exit (1 )
158
+ }
0 commit comments