Skip to content

Commit

Permalink
Ensure query command is consistent with use of flags and args
Browse files Browse the repository at this point in the history
  • Loading branch information
Zachary Scott committed Aug 6, 2018
1 parent 268a4e1 commit 9ae3a89
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,29 @@ import (

func newQueryCommand() *cobra.Command {
return &cobra.Command{
Use: "query",
Short: "Query the CircleCI GraphQL API using input from stdin.",
Use: "query PATH (use \"-\" for STDIN)",
Short: "Query the CircleCI GraphQL API.",
RunE: query,
Args: cobra.ExactArgs(1),
}
}

func query(cmd *cobra.Command, args []string) error {
var err error
var q []byte
c := client.NewClient(viper.GetString("endpoint"), Logger)

query, err := ioutil.ReadAll(os.Stdin)
if args[0] == "-" {
q, err = ioutil.ReadAll(os.Stdin)
} else {
q, err = ioutil.ReadFile(args[0])
}

if err != nil {
return errors.Wrap(err, "Unable to read query from stdin")
}

resp, err := client.Run(c, viper.GetString("token"), string(query))
resp, err := client.Run(c, viper.GetString("token"), string(q))
if err != nil {
return errors.Wrap(err, "Error occurred when running query")
}
Expand Down

0 comments on commit 9ae3a89

Please sign in to comment.