Skip to content

Commit

Permalink
Merge branch 'master' into better-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
codepope committed Jun 26, 2020
2 parents b9ef662 + d7a4370 commit 55c4ef6
Show file tree
Hide file tree
Showing 95 changed files with 5,473 additions and 1,488 deletions.
19 changes: 0 additions & 19 deletions .github/workflows/push.yml

This file was deleted.

32 changes: 32 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
on:
push:
tags:
- "v*"
name: Release
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master
- name: Unshallow
run: git fetch --prune --unshallow
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.14
- name: Docker Login
if: success() && startsWith(github.ref, 'refs/tags/v')
env:
DOCKER_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
run: |
echo "${DOCKER_PASSWORD}" | docker login --username "${DOCKER_USERNAME}" --password-stdin
- name: Run GoReleaser
if: success() && startsWith(github.ref, 'refs/tags/v')
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GORELEASER_GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ dist/
# generated docs
out
docstrings/gen.go
/.idea/*
/.idea/.gitignore
/.idea/dictionaries/dj.xml
/.idea/flyctl.iml
Expand Down
75 changes: 44 additions & 31 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,64 @@ before:
- go mod download
- go generate ./...
builds:
- env:
- CGO_ENABLED=0
goos:
- windows
- darwin
- linux
ignore:
- goos: darwin
goarch: 386
ldflags:
- -X github.com/superfly/flyctl/flyctl.BuildDate={{.Date}}
- -X github.com/superfly/flyctl/flyctl.Version={{ .Version }}
- -X github.com/superfly/flyctl/flyctl.Commit={{ .ShortCommit }}
- env:
- CGO_ENABLED=0
goos:
- windows
- darwin
- linux
ignore:
- goos: darwin
goarch: 386
ldflags:
- -X github.com/superfly/flyctl/flyctl.BuildDate={{.Date}}
- -X github.com/superfly/flyctl/flyctl.Version={{ .Version }}
- -X github.com/superfly/flyctl/flyctl.Commit={{ .ShortCommit }}
- -X github.com/superfly/flyctl/flyctl.Environment=production
archives:
- replacements:
darwin: macOS
linux: Linux
windows: Windows
386: i386
amd64: x86_64
files: [only-the-binary*]
wrap_in_directory: false
format: tar.gz
- id: binary
format: binary
files: [only-the-binary*]
- replacements:
darwin: macOS
linux: Linux
windows: Windows
386: i386
amd64: x86_64
files: [only-the-binary*]
wrap_in_directory: false
format: tar.gz
- id: binary
format: binary
files: [only-the-binary*]
replacements:
darwin: macOS
linux: Linux
windows: Windows
386: i386
amd64: x86_64
dockers:
- goos: linux
goarch: amd64
image_templates:
- "flyio/flyctl:latest"
- "flyio/flyctl:v{{ .Version }}"
checksum:
name_template: 'checksums.txt'
name_template: "checksums.txt"
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
- "^docs:"
- "^test:"
brews:
-
github:
- github:
owner: superfly
name: homebrew-tap
folder: Formula
homepage: https://fly.io
test: |
system "#{bin}/flyctl version"
# snapcrafts:
# -
# id: flyctl
Expand All @@ -65,4 +78,4 @@ brews:
# fly-config:
# interface: personal-files
# write:
# - $HOME/.fly
# - $HOME/.fly
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM golang:alpine as build
RUN apk --no-cache add ca-certificates

FROM scratch
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY flyctl /
ENTRYPOINT ["/flyctl"]
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
all: build cmddocs

generate:
@echo Running Generate for Help
go generate ./...

build: generate
@echo Running Build
go build -o bin/flyctl .

cmddocs: generate
sh scripts/generate_docs.sh
@echo Running Docs Generation
sh scripts/generate_docs.sh
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ flyctl is a command line interface for fly.io
```bash
brew install superfly/tap/flyctl
```
To upgrade to the latest version:

```bash
brew upgrade flyctl
```

## Install Script

Expand All @@ -19,19 +24,15 @@ Download `flyctl` and install into
Installing the latest version:

```bash
curl https://get.fly.io/flyctl.sh | sh
curl -L https://fly.io/install.sh | sh
```

Installing a specific version:

```bash
curl https://get.fly.io/flyctl.sh | sh -s v0.0.1
curl -L https://fly.io/install.sh | sh -s v0.0.1
```

Install into a bin directory other than `/usr/local/bin`:
```bash
BIN_DIR=~/.bin curl https://get.fly.io/flyctl.sh | sh
```
## Downloading from GitHub

Download the appropriate version from the [Releases](https://github.com/superfly/flyctl/releases) page of the `flyctl` GitHub repository.
Expand Down
3 changes: 3 additions & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ package api

import "errors"

// ErrNotFound - Error to return when something is not found
var ErrNotFound = errors.New("Not Found")

// ErrUnknown - Error to return when an unknown server error occurs
var ErrUnknown = errors.New("An unknown server error occured, please try again")
16 changes: 16 additions & 0 deletions api/casting.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package api

// IntPointer - Returns a pointer to an int
func IntPointer(val int) *int {
return &val
}

// BoolPointer - Returns a pointer to a bool
func BoolPointer(val bool) *bool {
return &val
}

// StringPointer - Returns a pointer to a string
func StringPointer(val string) *string {
return &val
}
17 changes: 14 additions & 3 deletions api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,43 @@ import (
"errors"
"fmt"
"net/http"
"os"
"regexp"
"strings"

"github.com/machinebox/graphql"
)

var baseURL string
var errorLog bool

func SetBaseURL(url string) {
baseURL = url
}

func SetErrorLog(log bool) {
errorLog = log
}

type Client struct {
httpClient *http.Client
client *graphql.Client
accessToken string
userAgent string
}

func NewClient(accessToken string, version string) (*Client, error) {
func NewClient(accessToken string, version string) *Client {
if accessToken == "" {
return nil, errors.New("No api access token available. Please login with 'flyctl auth signup' or 'flyctl auth login'")
}

httpClient, _ := newHTTPClient()

url := fmt.Sprintf("%s/api/v2/graphql", baseURL)
url := fmt.Sprintf("%s/graphql", baseURL)

client := graphql.NewClient(url, graphql.WithHTTPClient(httpClient))
userAgent := fmt.Sprintf("flyctl/%s", version)
return &Client{httpClient, client, accessToken, userAgent}, nil
return &Client{httpClient, client, accessToken, userAgent}
}

func (c *Client) NewRequest(q string) *graphql.Request {
Expand All @@ -58,6 +64,11 @@ func (c *Client) RunWithContext(ctx context.Context, req *graphql.Request) (Quer
if err != nil && strings.HasPrefix(err.Error(), "graphql: ") {
return resp, errors.New(strings.TrimPrefix(err.Error(), "graphql: "))
}

if resp.Errors != nil && errorLog {
fmt.Fprintf(os.Stderr, "Error: %+v\n", resp.Errors)
}

return resp, err
}

Expand Down

0 comments on commit 55c4ef6

Please sign in to comment.