Skip to content

Commit

Permalink
clean up output process
Browse files Browse the repository at this point in the history
  • Loading branch information
po3rin committed Dec 1, 2019
1 parent bc22c17 commit f7f540d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ $ gofmtmd testdata/testdata.md -r

# write result to file instead of stdout
$ gofmtmd testdata/testdata.md -w formatted.md

# you can use stdndard input
$ gofmtmd < testdata/testdata.md
$ echo "#hello" | gofmtmd
```

## Help
Expand Down
21 changes: 11 additions & 10 deletions cmd/gofmtmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var (

var rootCmd = &cobra.Command{
Use: "gofmtmd",
Version: "0.1.1",
Version: "0.1.2",
Short: "This CLI formats Go Code in Markdown.",
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -46,18 +46,19 @@ var rootCmd = &cobra.Command{
if err != nil {
log.Fatalf("[gofmtmd] failed to writes to %v: %v", filename, err)
}
}
if outputfile != "" {
err = ioutil.WriteFile(outputfile, out, 0644)
if err != nil {
log.Fatalf("[gofmtmd] failed to writes to %v: %v", filename, err)
}
return
}
}
if !replace && outputfile == "" {
writer := os.Stdout
fmt.Fprint(writer, string(out))
if outputfile != "" {
err := ioutil.WriteFile(outputfile, out, 0644)
if err != nil {
log.Fatalf("[gofmtmd] failed to writes to %v: %v", outputfile, err)
}
return
}

writer := os.Stdout
fmt.Fprint(writer, string(out))
},
}

Expand Down

0 comments on commit f7f540d

Please sign in to comment.