Skip to content

Commit

Permalink
Merge pull request #72 from containscafeine/accept_stdin
Browse files Browse the repository at this point in the history
add support for passing in input from STDIN
  • Loading branch information
kadel authored Mar 30, 2017
2 parents e541481 + c9e4481 commit 885542a
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions pkg/cmd/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"k8s.io/client-go/pkg/api"
"k8s.io/client-go/pkg/api/meta"
"k8s.io/client-go/pkg/runtime"
"os"
)

var (
Expand Down Expand Up @@ -62,12 +63,23 @@ func GetValidatedObject(v *viper.Viper, cmd *cobra.Command, out, outerr io.Write
}

var ocObjects []*object.OpenCompose

for _, file := range files {
data, err := ioutil.ReadFile(file)
if err != nil {
return nil, fmt.Errorf("unable to read file '%s': %s", file, err)
}
var data []byte
var err error

// Check if the passed resource points to STDIN or not
if file == "-" {
data, err = ioutil.ReadAll(os.Stdin)
if err != nil {
return nil, fmt.Errorf("unable to read from stdin: %s", err)
}
} else {
data, err = ioutil.ReadFile(file)
if err != nil {
return nil, fmt.Errorf("unable to read file '%s': %s", file, err)
}
}
decoder, err := encoding.GetDecoderFor(data)
if err != nil {
return nil, fmt.Errorf("could not find decoder for file '%s': %s", file, err)
Expand Down

0 comments on commit 885542a

Please sign in to comment.