Skip to content

Commit

Permalink
✨ Add -l flag Option
Browse files Browse the repository at this point in the history
  • Loading branch information
UltiRequiem committed Sep 7, 2021
1 parent 5b5d772 commit 1b22b6e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ A simple and extensible [yaml](https://yaml.org) formatter.

## Installation

With `go Install`:
With `go install`:

```bash
go install github.com/UltiRequiem/yamlfmt@latest
```

You can also use the binaries from
[releases](https://github.com/UltiRequiem/yamlfmt/releases).

## Usage

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

If you want to log the files that have been formatted, you can use the `-l` flag also.

- To format stdin and write to stdout:

```bash
Expand Down
10 changes: 8 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package cmd

import "os"
import (
"fmt"
"os"
)

func Init() {
overwrite, indent, multipleArgs, files := getParams()
overwrite, indent, log, multipleArgs, files := getParams()

if multipleArgs {
for _, file := range files {
formatFile(file, *indent, *overwrite)
if log {
fmt.Printf("%s formatted!\n", file)
}
}
} else {
formatStream(os.Stdin, os.Stdout, *indent)
Expand Down
5 changes: 3 additions & 2 deletions cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ import (
"gopkg.in/yaml.v3"
)

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

flag.Parse()

return overwrite, indent, flag.NArg() > 0, flag.Args()
return overwrite, indent, *log, flag.NArg() > 0, flag.Args()

}

Expand Down

0 comments on commit 1b22b6e

Please sign in to comment.