Skip to content

Commit

Permalink
feat: check: support directory
Browse files Browse the repository at this point in the history
Fixes sethvargo#28

Signed-off-by: Furkan <furkan.turkal@trendyol.com>
Co-authored-by: Batuhan <batuhan.apaydin@trendyol.com>
  • Loading branch information
Dentrax and developer-guy committed Jun 3, 2022
1 parent 0b958a5 commit 98c9f87
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
### Go
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
vendor/
ratchet

43 changes: 40 additions & 3 deletions command/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"flag"
"fmt"
"os"
"path/filepath"
"strings"

"github.com/sethvargo/ratchet/parser"
Expand All @@ -22,6 +23,7 @@ not communicate with upstream APIs or services.
EXAMPLES
ratchet check ./path/to/file.yaml
ratchet check ./path/to/dir
FLAGS
Expand Down Expand Up @@ -59,10 +61,45 @@ func (c *CheckCommand) Run(ctx context.Context, originalArgs []string) error {
return fmt.Errorf("expected exactly one argument, got %d", got)
}

inFile := args[0]
m, err := parseYAMLFile(inFile)
input := args[0]

fileInfo, err := os.Stat(input)
if err != nil {
return fmt.Errorf("input not found %w", err)
}

skipRoot := false
if fileInfo.IsDir() {
return filepath.Walk(input,
func(path string, info os.FileInfo, err error) error {
if !skipRoot {
skipRoot = true
return nil
}

if err != nil {
return err
}

err = c.Check(ctx, path)

if err == nil {
fmt.Println(fmt.Sprintf("[PASS] %s", path))
} else {
fmt.Println(fmt.Sprintf("[FAIL] %s : %v", path, err))
}

return err
})
}

return c.Check(ctx, input)
}

func (c *CheckCommand) Check(ctx context.Context, path string) error {
m, err := parseYAMLFile(path)
if err != nil {
return fmt.Errorf("failed to parse %s: %w", inFile, err)
return fmt.Errorf("failed to parse %s: %w", path, err)
}

par, err := parser.For(ctx, c.flagParser)
Expand Down

0 comments on commit 98c9f87

Please sign in to comment.