Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ To use `helmfmt` as a pre-commit hook, add the following to your `.pre-commit-co
```yaml
repos:
- repo: https://github.com/digitalstudium/helmfmt
rev: v0.4.1
rev: v0.4.2
hooks:
- id: helmfmt
```
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4.1
0.4.2
47 changes: 38 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,26 +109,28 @@ func run() int {
stat, _ := os.Stdin.Stat()
stdinPiped := (stat.Mode() & os.ModeCharDevice) == 0

if stdinPiped {
// Process from stdin
if len(args) > 0 {
return fmt.Errorf("cannot specify files when reading from stdin")
}
return processStdin(config)
}

// If --files flag is used, process the provided files
if files {
// Files mode
if len(args) == 0 {
// --files with no args means read filenames from stdin (pre-commit style)
if stdinPiped {
return processFilesFromStdin(config, stdout)
}
return fmt.Errorf("--files requires at least one file argument")
}
// --files with args means process those files
exitCode := process(args, stdout, config)
if exitCode != 0 {
os.Exit(exitCode)
}
return nil
}

// If stdin is piped and no --files flag, process stdin as content
if stdinPiped && len(args) == 0 {
return processStdin(config)
}

// Chart mode
if len(args) != 1 {
return fmt.Errorf("chart mode requires exactly one chart path")
Expand Down Expand Up @@ -163,6 +165,33 @@ func run() int {
return 0
}

func processFilesFromStdin(config *Config, stdout bool) error {
// Read filenames from stdin (one per line)
input, err := io.ReadAll(os.Stdin)
if err != nil {
return fmt.Errorf("error reading from stdin: %w", err)
}

lines := strings.Split(strings.TrimSpace(string(input)), "\n")
var filenames []string
for _, line := range lines {
line = strings.TrimSpace(line)
if line != "" {
filenames = append(filenames, line)
}
}

if len(filenames) == 0 {
return fmt.Errorf("no files provided via stdin")
}

exitCode := process(filenames, stdout, config)
if exitCode != 0 {
os.Exit(exitCode)
}
return nil
}

func processStdin(config *Config) error {
// Read all input from stdin
input, err := io.ReadAll(os.Stdin)
Expand Down