diff --git a/client/client.go b/client/client.go index b66298672..448500f93 100644 --- a/client/client.go +++ b/client/client.go @@ -8,17 +8,17 @@ import ( ) type Client struct { - host string - token string - client *graphql.Client - logger *logger.Logger + endpoint string + token string + client *graphql.Client + logger *logger.Logger } -func NewClient(host string, token string, logger *logger.Logger) *Client { +func NewClient(endpoint string, token string, logger *logger.Logger) *Client { return &Client{ - host, + endpoint, token, - graphql.NewClient(host + "/graphql"), + graphql.NewClient(endpoint), logger, } } @@ -30,8 +30,7 @@ func (c *Client) Run(query string) (map[string]interface{}, error) { ctx := context.Background() var resp map[string]interface{} - // TODO: fix wrapping logs with - c.logger.Info("Querying ", c.host, " with:\n\n", query, "\n\n") + c.logger.Info("Querying ", c.endpoint, " with:\n\n", query, "\n\n") err := c.client.Run(ctx, req, &resp) return resp, err } diff --git a/cmd/diagnostic.go b/cmd/diagnostic.go index 67219bbc9..dc974371e 100644 --- a/cmd/diagnostic.go +++ b/cmd/diagnostic.go @@ -12,13 +12,13 @@ var diagnosticCmd = &cobra.Command{ } func diagnostic(cmd *cobra.Command, args []string) { - host := viper.GetString("host") + endpoint := viper.GetString("endpoint") token := viper.GetString("token") Logger.Info("\n---\nCircleCI CLI Diagnostics\n---\n\n") Logger.Infof("Config found: `%v`\n", viper.ConfigFileUsed()) - Logger.Infof("Host is: %s\n", host) + Logger.Infof("GraphQL API endpoint: %s\n", endpoint) if token == "token" || token == "" { Logger.Info("Please set a token!") diff --git a/cmd/query.go b/cmd/query.go index 42f49dded..d66ba0c28 100644 --- a/cmd/query.go +++ b/cmd/query.go @@ -17,7 +17,7 @@ var queryCmd = &cobra.Command{ } func query(cmd *cobra.Command, args []string) { - client := client.NewClient(viper.GetString("host"), viper.GetString("token"), Logger) + client := client.NewClient(viper.GetString("endpoint"), viper.GetString("token"), Logger) query, err := ioutil.ReadAll(os.Stdin) Logger.FatalOnError("Something happened", err) diff --git a/cmd/root.go b/cmd/root.go index d04a4dbee..253791281 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -45,10 +45,10 @@ func init() { rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose logging.") Logger = logger.NewLogger(verbose) rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file (default is $HOME/.circleci/cli.yml)") - rootCmd.PersistentFlags().StringP("host", "H", "https://circleci.com", "the host of your CircleCI install") + rootCmd.PersistentFlags().StringP("endpoint", "e", "https://circleci.com/graphql", "the endpoint of your CircleCI GraphQL API") rootCmd.PersistentFlags().StringP("token", "t", "", "your token for using CircleCI") - Logger.FatalOnError("Error binding host flag", viper.BindPFlag("host", rootCmd.PersistentFlags().Lookup("host"))) + Logger.FatalOnError("Error binding endpoint flag", viper.BindPFlag("endpoint", rootCmd.PersistentFlags().Lookup("endpoint"))) Logger.FatalOnError("Error binding token flag", viper.BindPFlag("token", rootCmd.PersistentFlags().Lookup("token"))) } @@ -78,7 +78,7 @@ func readConfig() (err error) { } // read in environment variables that match - // set a prefix for config, i.e. CIRCLECI_CLI_HOST + // set a prefix for config, i.e. CIRCLECI_CLI_ENDPOINT viper.SetEnvPrefix("circleci_cli") viper.AutomaticEnv() @@ -117,12 +117,12 @@ func createConfig() (err error) { defer Logger.FatalOnError("Error closing config file", file.Close()) // read flag values - host := viper.GetString("host") + endpoint := viper.GetString("endpoint") token := viper.GetString("token") - if host == "host" || host == "" { - Logger.Info("Please enter the HTTP(S) host of your CircleCI installation:") - fmt.Scanln(&host) + if endpoint == "endpoint" || endpoint == "" { + Logger.Info("Please enter the HTTP(S) endpoint to your CircleCI GraphQL API:") + fmt.Scanln(&endpoint) Logger.Info("OK.\n") } @@ -133,7 +133,7 @@ func createConfig() (err error) { } // format input - configValues := fmt.Sprintf("host: %v\ntoken: %v\n", host, token) + configValues := fmt.Sprintf("endpoint: %v\ntoken: %v\n", endpoint, token) // write new config values to file if _, err = file.WriteString(configValues); err != nil {