Skip to content

Commit

Permalink
chore: apply suggestions
Browse files Browse the repository at this point in the history
google#179 (comment)

* Prefer basic formatter having mapstructure rather than yaml tag in command

* Rename resolved with print

* Add integration tests for loading config files
  • Loading branch information
kachick committed May 12, 2024
1 parent 43e12fd commit c228b70
Show file tree
Hide file tree
Showing 15 changed files with 117 additions and 13 deletions.
4 changes: 2 additions & 2 deletions command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (c *Command) Run() error {
if err != nil {
return err
}
fmt.Println(string(out))
fmt.Print(string(out))

formatterConfigMap, err := formatter.ConfigMap()
if err != nil {
Expand All @@ -185,7 +185,7 @@ func (c *Command) Run() error {
if err != nil {
return err
}
fmt.Println(string(out))
fmt.Print(string(out))
}

return nil
Expand Down
18 changes: 9 additions & 9 deletions docs/command-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ All flags must be specified **before** any path arguments.

These flags adjust the command's mode of operation. All of these flags are booleans.

| Name | Flag | Example | Description |
| :------------ | :--------------- | :------------------------ | :-------------------------------------------------------- |
| Help | `-help` | `yamlfmt -help` | Print the command usage information. |
| Print Version | `-version` | `yamlfmt -version` | Print the yamlfmt version. |
| Print Config | `-print_conf` | `yamlfmt -print_conf` | Print the merged configuration to use. |
| Dry Run | `-dry` | `yamlfmt -dry .` | Use [Dry Run](#dry-run) mode |
| Lint | `-lint` | `yamlfmt -lint .` | Use [Lint](#lint) mode |
| Quiet Mode | `-quiet` | `yamlfmt -dry -quiet .` | Use quiet mode. Only has effect in Dry Run or Lint modes. |
| Read Stdin | `-in` | `cat x.yaml \| yamlfmt -in` | Read input from stdin and output result to stdout. |
| Name | Flag | Example | Description |
| :------------ | :------------ | :-------------------------- | :-------------------------------------------------------- |
| Help | `-help` | `yamlfmt -help` | Print the command usage information. |
| Print Version | `-version` | `yamlfmt -version` | Print the yamlfmt version. |
| Print Config | `-print_conf` | `yamlfmt -print_conf` | Print the merged configuration to use. |
| Dry Run | `-dry` | `yamlfmt -dry .` | Use [Dry Run](#dry-run) mode |
| Lint | `-lint` | `yamlfmt -lint .` | Use [Lint](#lint) mode |
| Quiet Mode | `-quiet` | `yamlfmt -dry -quiet .` | Use quiet mode. Only has effect in Dry Run or Lint modes. |
| Read Stdin | `-in` | `cat x.yaml \| yamlfmt -in` | Read input from stdin and output result to stdout. |

### Configuration Flags

Expand Down
19 changes: 17 additions & 2 deletions integrationtest/command/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,24 @@ func TestDryQuiet(t *testing.T) {
}.Run(t)
}

func TestPrintConf(t *testing.T) {
func TestPrintConfFlags(t *testing.T) {
TestCase{
Dir: "print_conf",
Dir: "print_conf_flags",
Command: yamlfmtWithArgs("-print_conf -continue_on_error=true -formatter retain_line_breaks=true"),
Update: *updateFlag,
}.Run(t)
}

func TestPrintConfFile(t *testing.T) {
TestCase{
Dir: "print_conf_file",
Command: yamlfmtWithArgs("-print_conf"),
Update: *updateFlag,
}.Run(t)
}
func TestPrintConfFlagsAndFile(t *testing.T) {
TestCase{
Dir: "print_conf_flags_and_file",
Command: yamlfmtWithArgs("-print_conf -continue_on_error=true -formatter retain_line_breaks=true"),
Update: *updateFlag,
}.Run(t)
Expand Down
2 changes: 2 additions & 0 deletions integrationtest/command/testdata/print_conf_file/after/a.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a:
b: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a:
b: 1
Empty file.
26 changes: 26 additions & 0 deletions integrationtest/command/testdata/print_conf_file/stdout/stdout.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
continue_on_error: false
doublestar: true
exclude:
- '**/templates/*.yaml'
extensions:
- yaml
- yml
gitignore_excludes: false
gitignore_path: .my_gitignore
include: []
line_ending: crlf
output_format: default
regex_exclude: []
formatter:
disallow_anchors: false
drop_merge_tag: false
include_document_start: true
indent: 2
indentless_arrays: false
line_ending: crlf
max_line_length: 0
pad_line_comments: 1
retain_line_breaks: false
retain_line_breaks_single: true
scan_folded_as_literal: false
type: basic
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a:
b: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a:
b: 1
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
continue_on_error: true
doublestar: false
exclude: []
extensions:
- yaml
- yml
gitignore_excludes: false
gitignore_path: .gitignore
include: []
line_ending: lf
output_format: default
regex_exclude: []
formatter:
disallow_anchors: false
drop_merge_tag: false
include_document_start: false
indent: 2
indentless_arrays: false
line_ending: lf
max_line_length: 0
pad_line_comments: 1
retain_line_breaks: true
retain_line_breaks_single: false
scan_folded_as_literal: false
type: basic
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a:
b: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a:
b: 1
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
continue_on_error: true
doublestar: true
exclude:
- '**/templates/*.yaml'
extensions:
- yaml
- yml
gitignore_excludes: false
gitignore_path: .my_gitignore
include: []
line_ending: crlf
output_format: default
regex_exclude: []
formatter:
disallow_anchors: false
drop_merge_tag: false
include_document_start: true
indent: 2
indentless_arrays: false
line_ending: crlf
max_line_length: 0
pad_line_comments: 1
retain_line_breaks: true
retain_line_breaks_single: true
scan_folded_as_literal: false
type: basic

0 comments on commit c228b70

Please sign in to comment.