diff --git a/src/cmd/input.go b/src/cmd/input.go index c44b1d2f..b1549726 100644 --- a/src/cmd/input.go +++ b/src/cmd/input.go @@ -1,12 +1,13 @@ package cmd import ( + "bytes" "os" "github.com/rs/zerolog/log" - "github.com/creasty/defaults" "github.com/spf13/viper" + "gopkg.in/yaml.v3" ) var dataFile string @@ -30,13 +31,31 @@ func readInputConfig() { } func readResourceInput[T any]() (*T, error) { - readInputConfig() - var evt T - viper.Unmarshal(&evt) - if err := defaults.Set(&evt); err != nil { + var err error + var resource T + var yamlData []byte + + switch dataFile { + case ".": + yamlData, err = os.ReadFile("./data.yaml") + case "-": + if isStdInFromTerminal() { + log.Info().Msg("Reading input directly from command line... Press CTRL+D to stop typing") + } + buf := bytes.Buffer{} + _, err = buf.ReadFrom(os.Stdin) + yamlData = buf.Bytes() + default: + yamlData, err = os.ReadFile(dataFile) + } + if err != nil { + return nil, err + } + + if err := yaml.Unmarshal(yamlData, &resource); err != nil { return nil, err } - return &evt, nil + return &resource, nil } func isStdInFromTerminal() bool { diff --git a/src/cmd/team.go b/src/cmd/team.go index be5db3ff..8c22c295 100644 --- a/src/cmd/team.go +++ b/src/cmd/team.go @@ -17,7 +17,7 @@ var createTeamCmd = &cobra.Command{ Short: "Create a team", Example: `opslevel create team my-team -cat << EOF | opslevel create team my-team" -f - +cat << EOF | opslevel create team my-team -f - managerEmail: "manager@example.com" parentTeam: alias: "parent-team"