Skip to content

Commit bf2231a

Browse files
authored
bug: broken reading from stdin (-) (#704)
Signed-off-by: Tomasz Janiszewski <[email protected]>
1 parent b9cd03d commit bf2231a

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

e2etests/bats-tests.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,3 +1005,7 @@ get_value_from() {
10051005
print_info "${status}" "${output}" "${cmd}" "${tmp}"
10061006
[ "$status" -eq 0 ]
10071007
}
1008+
1009+
@test "flag-read-from-stdin" {
1010+
echo "---" | ${KUBE_LINTER_BIN} lint -
1011+
}

pkg/command/lint/command.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,12 @@ func Command() *cobra.Command {
8787
return err
8888
}
8989

90-
absArgs := []string{}
90+
absArgs := make([]string, 0, len(args))
9191
for _, arg := range args {
92+
if arg == lintcontext.ReadFromStdin {
93+
absArgs = append(absArgs, lintcontext.ReadFromStdin)
94+
continue
95+
}
9296
absArg, err := pathutil.GetAbsolutPath(arg)
9397
if err != nil {
9498
return err

pkg/lintcontext/create_contexts.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import (
1616
"k8s.io/apimachinery/pkg/runtime"
1717
)
1818

19+
// ReadFromStdin is a path used to indicate reading from os.Stdin
20+
const ReadFromStdin = "-"
21+
1922
var (
2023
knownYAMLExtensions = set.NewFrozenStringSet(".yaml", ".yml")
2124
)
@@ -41,16 +44,15 @@ func CreateContextsWithOptions(options Options, ignorePaths []string, filesOrDir
4144
contextsByDir := make(map[string]*lintContextImpl)
4245
fileOrDirsLoop:
4346
for _, fileOrDir := range filesOrDirs {
44-
// Stdin
45-
if fileOrDir == "-" {
46-
if _, alreadyExists := contextsByDir["-"]; alreadyExists {
47+
if fileOrDir == ReadFromStdin {
48+
if _, alreadyExists := contextsByDir[ReadFromStdin]; alreadyExists {
4749
continue
4850
}
4951
ctx := newCtx(options)
5052
if err := ctx.loadObjectsFromReader("<standard input>", os.Stdin); err != nil {
5153
return nil, err
5254
}
53-
contextsByDir["-"] = ctx
55+
contextsByDir[ReadFromStdin] = ctx
5456
continue
5557
}
5658

0 commit comments

Comments
 (0)