Skip to content

Commit

Permalink
Actually use host passed in by flag or config file
Browse files Browse the repository at this point in the history
TODO: I've left token out since it's unclear
      how api-service uses it..
  • Loading branch information
Zachary Scott committed May 30, 2018
1 parent 0cf26ca commit 6383dc6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
17 changes: 11 additions & 6 deletions cmd/diagnostic.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/machinebox/graphql"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

var diagnosticCmd = &cobra.Command{
Expand All @@ -17,9 +18,10 @@ var diagnosticCmd = &cobra.Command{
}

func diagnostic(cmd *cobra.Command, args []string) {
client := graphql.NewClient("https://circleci.com/graphql")

req := graphql.NewRequest(`
// TODO: Pass token once figure out how api-service uses it
host := viper.GetString("host") + "/graphql"
client := graphql.NewClient(host)
query := `
query IntrospectionQuery {
__schema {
queryType { name }
Expand All @@ -42,16 +44,19 @@ func diagnostic(cmd *cobra.Command, args []string) {
fields(includeDeprecated: true) {
name
}
}
`)
}`

req := graphql.NewRequest(query)

ctx := context.Background()
var resp map[string]interface{}

fmt.Println("Querying", host, "with:\n", query, "\n")
if err := client.Run(ctx, req, &resp); err != nil {
log.Fatal(err)
}

b, _ := json.MarshalIndent(resp, "", " ")
fmt.Print(string(b))
fmt.Println("Result: \n")
fmt.Println(string(b))
}
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func Execute() {
func init() {
cobra.OnInitialize(initConfig)

RootCmd.PersistentFlags().StringP("host", "", "host", "the host of your CircleCI install")
RootCmd.PersistentFlags().StringP("token", "t", "token", "your token for using CircleCI")
RootCmd.PersistentFlags().StringP("host", "H", "https://circleci.com", "the host of your CircleCI install")
RootCmd.PersistentFlags().StringP("token", "t", "", "your token for using CircleCI")

viper.BindPFlag("host", RootCmd.PersistentFlags().Lookup("host"))
viper.BindPFlag("token", RootCmd.PersistentFlags().Lookup("token"))
Expand Down

0 comments on commit 6383dc6

Please sign in to comment.