Skip to content

Commit

Permalink
allow reading config from stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
johnswanson committed Jul 16, 2018
1 parent 31c0c3d commit 3c18bba
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package api
import (
"context"
"io/ioutil"
"os"
"strings"

"github.com/CircleCI-Public/circleci-cli/client"
Expand Down Expand Up @@ -36,8 +37,13 @@ func (response ConfigResponse) ToError() error {
}

func loadYaml(path string) (string, error) {

config, err := ioutil.ReadFile(path)
var err error
var config []byte
if path == "-" {
config, err = ioutil.ReadAll(os.Stdin)
} else {
config, err = ioutil.ReadFile(path)
}

if err != nil {
return "", errors.Wrapf(err, "Could not load config file at %s", path)
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func MakeCommands() *cobra.Command {
rootCmd.PersistentFlags().BoolP("verbose", "v", false, "Enable verbose logging.")
rootCmd.PersistentFlags().StringP("endpoint", "e", defaultEndpoint, "the endpoint of your CircleCI GraphQL API")
rootCmd.PersistentFlags().StringP("token", "t", "", "your token for using CircleCI")
rootCmd.PersistentFlags().StringVarP(&configPath, "config", "c", configPath, "path to build config")
rootCmd.PersistentFlags().StringVarP(&configPath, "config", "c", configPath, "path to build config. '-' reads from STDIN")

for _, flag := range []string{"endpoint", "token", "verbose"} {
bindCobraFlagToViper(rootCmd, flag)
Expand Down

0 comments on commit 3c18bba

Please sign in to comment.