feat: set up project skeleton for new CLI (#1)

* docs: fill in README
* feat: initial setup of CLI, with help + version commands
* build: add linters and Makefile
* build: add initial CircleCI workflow
This commit is contained in:
Daniel Moran 2021-04-12 13:39:09 -04:00 committed by GitHub
parent 493bb6a925
commit 8c062cacf0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 275 additions and 2 deletions

48
.circleci/config.yml Normal file
View File

@ -0,0 +1,48 @@
version: "2.1"
workflows:
version: 2
build:
jobs:
- lint
- build
- test
jobs:
lint:
docker:
- image: cimg/go:1.16.3
working_directory: /home/circleci/go/src/github.com/influxdata/influx-cli
steps:
- checkout
- run: make vet
- run: make checkfmt
- run: make checktidy
- run: make staticcheck
build:
docker:
- image: cimg/go:1.16.3
working_directory: /home/circleci/go/src/github.com/influxdata/influx-cli
steps:
- checkout
- run: make influx
test:
docker:
- image: cimg/go:1.16.3
working_directory: /home/circleci/go/src/github.com/influxdata/influx-cli
steps:
- checkout
- run:
name: Run parallel race tests
command: |
mkdir -p /tmp/test-results
GO_TEST_CMD="gotestsum --format standard-quiet --junitfile /tmp/test-results/gotestsum.xml --"
TESTFILES=($(go list ./... | circleci tests split --split-by=timings))
make GO_TEST="$GO_TEST_CMD" GO_TEST_PATHS="${TESTFILES[*]}" test-race
- store_artifacts:
path: /tmp/test-results
destination: raw-test-output
- store_test_results:
path: /tmp/test-results

5
.gitignore vendored
View File

@ -4,6 +4,7 @@
*.dll
*.so
*.dylib
bin/
# Test binary, built with `go test -c`
*.test
@ -11,5 +12,5 @@
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Dependency directories (remove the comment below to include it)
# vendor/
# Dependency directories
vendor/

68
Makefile Normal file
View File

@ -0,0 +1,68 @@
### Environment setup
export GOPATH=$(shell go env GOPATH)
export GOOS=$(shell go env GOOS)
export GOARCH=$(shell go env GOARCH)
export GOVERSION=$(shell go list -m -f '{{.GoVersion}}')
ifeq ($(OS), Windows_NT)
VERSION := $(shell git describe --exact-match --tags 2>nil)
else
VERSION := $(shell git describe --exact-match --tags 2>/dev/null)
endif
COMMIT := $(shell git rev-parse --short HEAD)
LDFLAGS := $(LDFLAGS) -X main.commit=$(COMMIT) -X main.date=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
ifdef VERSION
LDFLAGS += -X main.version=$(VERSION)
endif
export GO_BUILD=go build -ldflags "$(LDFLAGS)"
SOURCES := $(shell find . -name '*.go' -not -name '*_test.go') go.mod go.sum
SOURCES_NO_VENDOR := $(shell find . -path ./vendor -prune -o -name "*.go" -not -name '*_test.go' -print)
# Allow for `go test` to be swapped out by other tooling, i.e. `gotestsum`
export GO_TEST=go test
# Allow for a subset of tests to be specified.
GO_TEST_PATHS=./...
### Build / dependency management
fmt: $(SOURCES_NO_VENDOR)
gofmt -w -s $^
go run github.com/daixiang0/gci -w $^
bin/$(GOOS)/influx: $(SOURCES)
$(GO_BUILD) -o $@ ./cmd/$(shell basename "$@")
influx: bin/$(GOOS)/influx
vendor: go.mod go.sum
go mod vendor
build: fmt influx
clean:
$(RM) -r bin
$(RM) -r vendor
### Linters
checkfmt:
./etc/checkfmt.sh
checktidy:
./etc/checktidy.sh
staticcheck: $(SOURCES) vendor
go run honnef.co/go/tools/cmd/staticcheck -go $(GOVERSION) ./...
vet:
go vet ./...
# Testing
test:
$(GO_TEST) $(GO_TEST_PATHS)
test-race:
$(GO_TEST) -v -race -count=1 $(GO_TEST_PATHS)
### List of all targets that don't produce a file
.PHONY: influx fmt build checkfmt checktidy staticcheck vet test test-race

View File

@ -1,2 +1,11 @@
# influx-cli
CLI for managing resources in InfluxDB v2
## Status
This is a work-in-progress effort to decouple the `influx` CLI from the OSS `influxdb` codebase.
Our goals are to:
1. Make it easier to keep the CLI up-to-date with InfluxDB Cloud API changes
2. Enable faster turn-around on fixes/features that only affect the CLI
3. Allow the CLI to be built & released for a wider range of platforms than the server can support

44
cmd/influx/main.go Normal file
View File

@ -0,0 +1,44 @@
package main
import (
"fmt"
"os"
"time"
"github.com/urfave/cli/v2"
)
var (
version = "dev"
commit = "none"
date = ""
)
func main() {
if len(date) == 0 {
date = time.Now().UTC().Format(time.RFC3339)
}
cli.VersionFlag = nil
app := cli.App{
Name: "influx",
Usage: "Influx Client",
UsageText: "influx [command]",
Commands: []*cli.Command{
{
Name: "version",
Usage: "Print the influx CLI version",
Action: func(*cli.Context) error {
fmt.Printf("Influx CLI %s (git: %s) build_date: %s\n", version, commit, date)
return nil
},
},
},
}
if err := app.Run(os.Args); err != nil {
_, _ = fmt.Fprintf(os.Stderr, "Error: %v", err)
os.Exit(1)
}
}

22
etc/checkfmt.sh Executable file
View File

@ -0,0 +1,22 @@
#!/bin/bash
HAS_FMT_ERR=0
# For every Go file in the project, excluding vendor...
for file in $(go list -f '{{$dir := .Dir}}{{range .GoFiles}}{{printf "%s/%s\n" $dir .}}{{end}}' ./...); do
# ... if file does not contain standard generated code comment (https://golang.org/s/generatedcode)...
if ! grep -Exq '^// Code generated .* DO NOT EDIT\.$' $file; then
FMT_OUT="$(gofmt -l -d -e $file)" # gofmt exits 0 regardless of whether it's formatted.
GCI_OUT="$(go run github.com/daixiang0/gci -d $file)"
if [[ -n "$FMT_OUT" || -n "$GCI_OUT" ]]; then
HAS_FMT_ERR=1
echo "Not formatted: $file"
fi
fi
done
if [ "$HAS_FMT_ERR" -eq "1" ]; then
echo 'Commit includes files that are not formatted' && \
echo 'run "make fmt"' && \
echo ''
fi
exit "$HAS_FMT_ERR"

11
etc/checktidy.sh Executable file
View File

@ -0,0 +1,11 @@
#!/bin/bash
set -e
export GO111MODULE=on
go mod tidy
if ! git --no-pager diff --exit-code -- go.mod go.sum; then
>&2 echo "modules are not tidy, please run 'go mod tidy'"
exit 1
fi

9
go.mod Normal file
View File

@ -0,0 +1,9 @@
module github.com/influxdata/influx-cli/v2
go 1.16
require (
github.com/daixiang0/gci v0.2.8
github.com/urfave/cli/v2 v2.3.0
honnef.co/go/tools v0.1.3
)

46
go.sum Normal file
View File

@ -0,0 +1,46 @@
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/daixiang0/gci v0.2.8 h1:1mrIGMBQsBu0P7j7m1M8Lb+ZeZxsZL+jyGX4YoMJJpg=
github.com/daixiang0/gci v0.2.8/go.mod h1:+4dZ7TISfSmqfAGv59ePaHfNzgGtIkHAhhdKggP1JAc=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20201118003311-bd56c0adb394/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY=
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
honnef.co/go/tools v0.1.3 h1:qTakTkI6ni6LFD5sBwwsdSO+AQqbSIxOauHTTQKZ/7o=
honnef.co/go/tools v0.1.3/go.mod h1:NgwopIslSNH47DimFoV78dnkksY2EFtX0ajyb3K/las=

15
tools.go Normal file
View File

@ -0,0 +1,15 @@
//+build tools
package influxcli
// This package is a workaround for adding additional paths to the go.mod file
// and ensuring they stay there. The build tag ensures this file never gets
// compiled, but the go module tool will still look at the dependencies and
// add/keep them in go.mod so we can version these paths along with our other
// dependencies. When we run build on any of these paths, we get the version
// that has been specified in go.mod rather than the master copy.
import (
_ "github.com/daixiang0/gci"
_ "honnef.co/go/tools/cmd/staticcheck"
)