Skip to content

Commit 3a90629

Browse files
committed
Remove trim flag as its not properly supported by the cli package
1 parent 8aa69fc commit 3a90629

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

yaml.go

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,6 @@ func main() {
3030
},
3131
}
3232
app.Action = readProperty
33-
app.Flags = []cli.Flag{
34-
cli.StringFlag{
35-
Name: "trim, t",
36-
Value: "true",
37-
Usage: "trim output",
38-
},
39-
}
4033
app.Run(os.Args)
4134
}
4235

@@ -47,13 +40,13 @@ func readProperty(c *cli.Context) {
4740
readYaml(c, &parsedData)
4841

4942
if len(c.Args()) == 1 {
50-
printYaml(parsedData, c.Bool("trim"))
43+
printYaml(parsedData)
5144
os.Exit(0)
5245
}
5346

5447
var paths = parsePath(c.Args()[1])
5548

56-
printYaml(readMap(parsedData, paths[0], paths[1:len(paths)]), c.Bool("trim"))
49+
printYaml(readMap(parsedData, paths[0], paths[1:len(paths)]))
5750
}
5851

5952
func writeProperty(c *cli.Context) {
@@ -68,7 +61,7 @@ func writeProperty(c *cli.Context) {
6861

6962
write(parsedData, paths[0], paths[1:len(paths)], getValue(c.Args()[2]))
7063

71-
printYaml(parsedData, c.Bool("trim"))
64+
printYaml(parsedData)
7265
}
7366

7467
func getValue(argument string) interface{} {
@@ -88,16 +81,15 @@ func getValue(argument string) interface{} {
8881
return argument[1 : len(argument)-1]
8982
}
9083

91-
func printYaml(context interface{}, trim bool) {
84+
func printYaml(context interface{}) {
9285
out, err := yaml.Marshal(context)
9386
if err != nil {
9487
log.Fatalf("error printing yaml: %v", err)
9588
}
9689
outStr := string(out)
97-
if trim {
98-
outStr = strings.Trim(outStr, "\n ")
99-
}
100-
fmt.Println(outStr)
90+
// trim the trailing new line as it's easier for a script to add
91+
// it in if required than to remove it
92+
fmt.Println(strings.Trim(outStr, "\n "))
10193
}
10294

10395
func readYaml(c *cli.Context, parsedData *map[interface{}]interface{}) {

0 commit comments

Comments
 (0)