From 9ae3a89767260f8bb54a6af3ce3c6780839d984e Mon Sep 17 00:00:00 2001 From: Zachary Scott Date: Fri, 3 Aug 2018 16:14:31 +0900 Subject: [PATCH] Ensure `query` command is consistent with use of flags and args --- cmd/query.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) 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") }