-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from circleci/init
CIRCLE-11398: User can install CLI that will talk to registry
- Loading branch information
Showing
488 changed files
with
230,893 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
build/ | ||
TODO |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Gopkg.toml example | ||
# | ||
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md | ||
# for detailed Gopkg.toml documentation. | ||
# | ||
# required = ["github.com/user/thing/cmd/thing"] | ||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project" | ||
# version = "1.0.0" | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project2" | ||
# branch = "dev" | ||
# source = "github.com/myfork/project2" | ||
# | ||
# [[override]] | ||
# name = "github.com/x/y" | ||
# version = "2.4.0" | ||
# | ||
# [prune] | ||
# non-go = false | ||
# go-tests = true | ||
# unused-packages = true | ||
|
||
|
||
[[constraint]] | ||
name = "github.com/machinebox/graphql" | ||
branch = "master" | ||
|
||
[[constraint]] | ||
name = "github.com/spf13/cobra" | ||
version = "0.0.3" | ||
|
||
[[constraint]] | ||
name = "github.com/spf13/viper" | ||
version = "1.0.2" | ||
|
||
[prune] | ||
go-tests = true | ||
unused-packages = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
VERSION=0.1 | ||
DATE = $(shell date "+%FT%T%z") | ||
SHA=$(shell git rev-parse --short HEAD) | ||
|
||
GOFILES = $(shell find . -name '*.go' -not -path './vendor/*') | ||
|
||
CLIPATH=github.com/circleci/cli | ||
|
||
EXECUTABLE=cli | ||
BUILD_DIR=build | ||
|
||
.PHONY: build/linux | ||
$(BUILD_DIR)/%/amd64/$(EXECUTABLE): $(GOFILES) | ||
GOOS=$* GOARCH=amd64 CGO_ENABLED=0 go build $(LDFLAGS) -o $(BUILD_DIR)/$*/amd64/$(EXECUTABLE) . | ||
|
||
.PHONY: build | ||
build: $(BUILD_DIR)/darwin/amd64/$(EXECUTABLE) $(BUILD_DIR)/linux/amd64/$(EXECUTABLE) | ||
|
||
.PHONY: clean | ||
clean: | ||
go clean | ||
rm -rf $(BUILD_DIR) | ||
|
||
.PHONY: test | ||
test: | ||
go test -short ./... | ||
|
||
.PHONY: cover | ||
coverage: | ||
go test -coverprofile=coverage.txt -covermode=count ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# circleci/cli | ||
|
||
Summary | ||
|
||
## Requirements | ||
|
||
* Go 1.9+ | ||
* Make | ||
* ... | ||
|
||
It's written in Go. If you are new to Go, we recommend the following resources: | ||
|
||
* [A Tour of Go](https://tour.golang.org/welcome/1) | ||
* [The Go documentation](https://golang.org/doc/) | ||
|
||
## Development Workflow | ||
|
||
### 1. Go Dependencies | ||
|
||
Install `dep`: | ||
https://github.com/golang/dep | ||
|
||
On MacOS: | ||
|
||
``` | ||
$ brew install dep | ||
$ brew upgrade dep | ||
``` | ||
|
||
On Linux, etc: | ||
|
||
``` | ||
$ curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh | ||
``` | ||
|
||
Ensure dependencies are installed: | ||
|
||
``` | ||
$ dep ensure | ||
``` | ||
|
||
### 2. Build it | ||
|
||
``` | ||
$ make | ||
``` | ||
|
||
### 3. Run Diagnostic check | ||
|
||
``` | ||
$ ./build/target/linux/amd64/cli diagnostic | ||
Please enter your CircleCI API token: | ||
OK. | ||
Your configuration has been created in `/home/zzak/.circleci/cli.yml`. | ||
It can edited manually for advanced settings. | ||
--- | ||
CircleCI CLI Diagnostics | ||
--- | ||
Config found: `/home/zzak/.circleci/cli.yml` | ||
Host is: https://circleci.com | ||
OK, got a token. | ||
``` | ||
|
||
## Known Issues | ||
|
||
* ... | ||
|
||
## Doc | ||
|
||
You can view godoc of cli in your browser. | ||
|
||
1. Run `godoc -http=:6060` | ||
2. Access http://localhost:6060/pkg/github.com/circleci/cli/ | ||
|
||
## Editor support | ||
|
||
Go has great tooling for editors. | ||
|
||
``` | ||
$ go get golang.org/x/tools/cmd/goimports | ||
``` | ||
|
||
More [here](https://blog.golang.org/go-fmt-your-code). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
var diagnosticCmd = &cobra.Command{ | ||
Use: "diagnostic", | ||
Short: "Check the status of your CircleCI CLI.", | ||
Run: diagnostic, | ||
} | ||
|
||
func diagnostic(cmd *cobra.Command, args []string) { | ||
host := viper.GetString("host") | ||
token := viper.GetString("token") | ||
|
||
fmt.Printf("\n---\nCircleCI CLI Diagnostics\n---\n\n") | ||
fmt.Printf("Config found: `%v`\n", viper.ConfigFileUsed()) | ||
|
||
if host == "host" || host == "" { | ||
fmt.Println("Please set a host!") | ||
} else { | ||
fmt.Printf("Host is: %s\n", host) | ||
} | ||
|
||
if token == "token" || token == "" { | ||
fmt.Println("Please set a token!") | ||
} else { | ||
fmt.Println("OK, got a token.") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"log" | ||
|
||
"github.com/machinebox/graphql" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
var queryCmd = &cobra.Command{ | ||
Use: "query", | ||
Short: "Query the CircleCI GraphQL API.", | ||
Run: query, | ||
} | ||
|
||
func query(cmd *cobra.Command, args []string) { | ||
host := viper.GetString("host") | ||
token := viper.GetString("token") | ||
client := graphql.NewClient(host + "/graphql") | ||
|
||
query := ` | ||
query IntrospectionQuery { | ||
__schema { | ||
queryType { name } | ||
mutationType { name } | ||
subscriptionType { name } | ||
types { | ||
...FullType | ||
} | ||
directives { | ||
name | ||
description | ||
} | ||
} | ||
} | ||
fragment FullType on __Type { | ||
kind | ||
name | ||
description | ||
fields(includeDeprecated: true) { | ||
name | ||
} | ||
}` | ||
|
||
req := graphql.NewRequest(query) | ||
req.Header.Set("Authorization", token) | ||
|
||
ctx := context.Background() | ||
var resp map[string]interface{} | ||
|
||
fmt.Print("Querying ", host, " with:\n\n", query, "\n\n") | ||
if err := client.Run(ctx, req, &resp); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
b, _ := json.MarshalIndent(resp, "", " ") | ||
fmt.Print("Result: \n\n") | ||
fmt.Println(string(b)) | ||
} |
Oops, something went wrong.