Skip to content

Commit 1b22b6e

Browse files
committed
✨ Add -l flag Option
1 parent 5b5d772 commit 1b22b6e

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@ A simple and extensible [yaml](https://yaml.org) formatter.
1010

1111
## Installation
1212

13-
With `go Install`:
13+
With `go install`:
1414

1515
```bash
1616
go install github.com/UltiRequiem/yamlfmt@latest
1717
```
1818

19+
You can also use the binaries from
20+
[releases](https://github.com/UltiRequiem/yamlfmt/releases).
21+
1922
## Usage
2023

2124
- To format one or more files and write to stdout:
@@ -30,6 +33,8 @@ go install github.com/UltiRequiem/yamlfmt@latest
3033
yamlfmt -w a.yaml b.yaml c.yaml
3134
```
3235

36+
If you want to log the files that have been formatted, you can use the `-l` flag also.
37+
3338
- To format stdin and write to stdout:
3439

3540
```bash

cmd/root.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
package cmd
22

3-
import "os"
3+
import (
4+
"fmt"
5+
"os"
6+
)
47

58
func Init() {
6-
overwrite, indent, multipleArgs, files := getParams()
9+
overwrite, indent, log, multipleArgs, files := getParams()
710

811
if multipleArgs {
912
for _, file := range files {
1013
formatFile(file, *indent, *overwrite)
14+
if log {
15+
fmt.Printf("%s formatted!\n", file)
16+
}
1117
}
1218
} else {
1319
formatStream(os.Stdin, os.Stdout, *indent)

cmd/utils.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ import (
1111
"gopkg.in/yaml.v3"
1212
)
1313

14-
func getParams() (*bool, *int, bool, []string) {
14+
func getParams() (*bool, *int, bool, bool, []string) {
1515
overwrite := flag.Bool("w", false, "Overwrite the input file")
1616
indent := flag.Int("indent", 2, "Default indent")
17+
log := flag.Bool("l", false, "Log when a file is formatted")
1718

1819
flag.Parse()
1920

20-
return overwrite, indent, flag.NArg() > 0, flag.Args()
21+
return overwrite, indent, *log, flag.NArg() > 0, flag.Args()
2122

2223
}
2324

0 commit comments

Comments
 (0)