Skip to content

Commit

Permalink
Remove trim flag as its not properly supported by the cli package
Browse files Browse the repository at this point in the history
  • Loading branch information
mikefarah committed Oct 3, 2015
1 parent 8aa69fc commit 3a90629
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ func main() {
},
}
app.Action = readProperty
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "trim, t",
Value: "true",
Usage: "trim output",
},
}
app.Run(os.Args)
}

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

if len(c.Args()) == 1 {
printYaml(parsedData, c.Bool("trim"))
printYaml(parsedData)
os.Exit(0)
}

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

printYaml(readMap(parsedData, paths[0], paths[1:len(paths)]), c.Bool("trim"))
printYaml(readMap(parsedData, paths[0], paths[1:len(paths)]))
}

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

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

printYaml(parsedData, c.Bool("trim"))
printYaml(parsedData)
}

func getValue(argument string) interface{} {
Expand All @@ -88,16 +81,15 @@ func getValue(argument string) interface{} {
return argument[1 : len(argument)-1]
}

func printYaml(context interface{}, trim bool) {
func printYaml(context interface{}) {
out, err := yaml.Marshal(context)
if err != nil {
log.Fatalf("error printing yaml: %v", err)
}
outStr := string(out)
if trim {
outStr = strings.Trim(outStr, "\n ")
}
fmt.Println(outStr)
// trim the trailing new line as it's easier for a script to add
// it in if required than to remove it
fmt.Println(strings.Trim(outStr, "\n "))
}

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

0 comments on commit 3a90629

Please sign in to comment.