diff --git a/pkg/config/config.go b/pkg/config/config.go index 746bef9581..709a6ef17e 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -46,11 +46,19 @@ func loadRawMessages(src []string) ([]json.RawMessage, error) { var raws []json.RawMessage for _, p := range src { + if p == "-" { + r, err := loadRaw(os.Stdin) + if err != nil { + return nil, err + } + raws = append(raws, r...) + continue + } p, err := path.Expand(p) if err != nil { return nil, err } - r, err := loadRawConfig(p) + r, err := loadRawFromFile(p) if err != nil { return nil, err } @@ -426,8 +434,7 @@ func FilterWithoutTypeFromContext[T InternalObject](ctx context.Context) (out [] return FilterWithoutType[T](objs) } -func loadRawConfig(p string) ([]json.RawMessage, error) { - var raws []json.RawMessage +func loadRawFromFile(p string) ([]json.RawMessage, error) { file, err := os.Open(p) if err != nil { return nil, err @@ -435,10 +442,15 @@ func loadRawConfig(p string) ([]json.RawMessage, error) { defer func() { _ = file.Close() }() - decoder := utilyaml.NewYAMLToJSONDecoder(file) + return loadRaw(file) +} + +func loadRaw(r io.Reader) ([]json.RawMessage, error) { + var raws []json.RawMessage + decoder := utilyaml.NewYAMLToJSONDecoder(r) for { var raw json.RawMessage - err = decoder.Decode(&raw) + err := decoder.Decode(&raw) if err != nil { if errors.Is(err, io.EOF) { break diff --git a/pkg/config/flags.go b/pkg/config/flags.go index 135045f27c..50b978e140 100644 --- a/pkg/config/flags.go +++ b/pkg/config/flags.go @@ -42,6 +42,9 @@ func InitFlags(ctx context.Context, flags *pflag.FlagSet) (context.Context, erro } configPaths := make([]string, 0, len(*config)) for _, c := range *config { + if c == "-" { + configPaths = append(configPaths, c) + } configPath, err := path.Expand(c) if err != nil { return nil, err