diff --git a/cmd/query.go b/cmd/query.go index 988e31d20..4cd652034 100644 --- a/cmd/query.go +++ b/cmd/query.go @@ -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") }