Skip to content

Commit f7f540d

Browse files
committed
clean up output process
1 parent bc22c17 commit f7f540d

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ $ gofmtmd testdata/testdata.md -r
2020

2121
# write result to file instead of stdout
2222
$ gofmtmd testdata/testdata.md -w formatted.md
23+
24+
# you can use stdndard input
25+
$ gofmtmd < testdata/testdata.md
26+
$ echo "#hello" | gofmtmd
2327
```
2428

2529
## Help

cmd/gofmtmd/main.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var (
1717

1818
var rootCmd = &cobra.Command{
1919
Use: "gofmtmd",
20-
Version: "0.1.1",
20+
Version: "0.1.2",
2121
Short: "This CLI formats Go Code in Markdown.",
2222
Args: cobra.MaximumNArgs(1),
2323
Run: func(cmd *cobra.Command, args []string) {
@@ -46,18 +46,19 @@ var rootCmd = &cobra.Command{
4646
if err != nil {
4747
log.Fatalf("[gofmtmd] failed to writes to %v: %v", filename, err)
4848
}
49-
}
50-
if outputfile != "" {
51-
err = ioutil.WriteFile(outputfile, out, 0644)
52-
if err != nil {
53-
log.Fatalf("[gofmtmd] failed to writes to %v: %v", filename, err)
54-
}
49+
return
5550
}
5651
}
57-
if !replace && outputfile == "" {
58-
writer := os.Stdout
59-
fmt.Fprint(writer, string(out))
52+
if outputfile != "" {
53+
err := ioutil.WriteFile(outputfile, out, 0644)
54+
if err != nil {
55+
log.Fatalf("[gofmtmd] failed to writes to %v: %v", outputfile, err)
56+
}
57+
return
6058
}
59+
60+
writer := os.Stdout
61+
fmt.Fprint(writer, string(out))
6162
},
6263
}
6364

0 commit comments

Comments
 (0)