-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/cue: allow "fmt" to show unformatted files
Adds a --check flag that will cause cue to fail with exit code 1 in case any files require formatting. A list of non formatted files will be displayed, line by line, to stdout. Also, a typo is fixed in cue/ast/ast.go. resolves #363. Change-Id: I27c8e9b18bb01f981cd061a23ee3323bc403c9a9 Signed-off-by: Noam Dolovich <noam.tzvi.dolovich@gmail.com>
- Loading branch information
Showing
4 changed files
with
77 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# succeeds when file is formatted | ||
exec cue fmt --check formatted.cue | ||
|
||
# files are not modified | ||
exec stat -f %c formatted.cue | ||
cp stdout formatted_time_before | ||
exec cue fmt formatted.cue | ||
exec stat -f %c formatted.cue | ||
cmp stdout formatted_time_before | ||
|
||
stdin formatted.cue | ||
exec cue fmt --check - | ||
|
||
-- formatted.cue -- | ||
foo: "bar" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# fails and displays non formatted files | ||
! exec cue fmt --check not_formatted.cue another_not_formatted.cue | ||
cp stdout actual-stdout | ||
grep not_formatted.cue actual-stdout | ||
grep another_not_formatted.cue actual-stdout | ||
! grep correct.cue actual-stdout | ||
|
||
# stdin fails with no output | ||
stdin not_formatted.cue | ||
! exec cue fmt --check - | ||
cmp stdout expect-empty-stdout | ||
|
||
-- correct.cue -- | ||
foo: "bar" | ||
-- not_formatted.cue -- | ||
foo: "bar" | ||
-- another_not_formatted.cue -- | ||
bar: "baz" | ||
x: 1 | ||
-- expect-empty-stdout -- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters