Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup and stabilize (hopefully) #36

Merged
merged 5 commits into from
Nov 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
doc
tmp
pkg
*.gem
*.pid
coverage
coverage.data
Expand All @@ -14,8 +13,6 @@ build/*
profile
.console_history
.sass-cache/*
.rake_tasks~
*.log.lck
solr/
.jhw-cache/
jhw.*
Expand All @@ -26,4 +23,5 @@ generated/
.vendor/
bin/*
gin-bin
grifts/
.idea/
.vscode
30 changes: 30 additions & 0 deletions .goreleaser.yml.plush
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
builds:
-
goos:
- darwin
- linux
- windows
env:
- CGO_ENABLED=0
main: main.go

checksum:
name_template: 'checksums.txt'

snapshot:
name_template: "{{ .Tag }}-next"

changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
<%= if (brew) { %>
brews:
-
name: homebrew-tap
github:
owner: markbates
name: homebrew-tap
<% } %>
35 changes: 17 additions & 18 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
Copyright (c) 2016 Mark Bates
The MIT License (MIT)

MIT License
Copyright (c) 2019 Mark Bates

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
52 changes: 40 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,38 +1,66 @@
TAGS ?= "sqlite"
GO_BIN ?= go
TAGS ?= ""
GO_BIN ?= "go"

install:
$(GO_BIN) install -v ./grift
$(GO_BIN) install -tags ${TAGS} -v ./.
make tidy

deps:
$(GO_BIN) get github.com/gobuffalo/release
$(GO_BIN) get -tags ${TAGS} -t ./...
tidy:
ifeq ($(GO111MODULE),on)
$(GO_BIN) mod tidy
else
echo skipping go mod tidy
endif

deps:
$(GO_BIN) get -tags ${TAGS} -t ./...
make tidy

build:
$(GO_BIN) build -v .
make tidy

test:
$(GO_BIN) test -tags ${TAGS} ./...
$(GO_BIN) test -cover -tags ${TAGS} ./...
make tidy

ci-deps:
$(GO_BIN) get -tags ${TAGS} -t ./...

ci-test:
$(GO_BIN) test -tags ${TAGS} -race ./...

cov:
$(GO_BIN) test -coverprofile cover.out -tags ${TAGS} ./...
go tool cover -html cover.out
make tidy

lint:
go get github.com/golangci/golangci-lint/cmd/golangci-lint
golangci-lint run --enable-all
make tidy

update:
$(GO_BIN) get -u -tags ${TAGS}
ifeq ($(GO111MODULE),on)
rm go.*
$(GO_BIN) mod init
$(GO_BIN) mod tidy
else
$(GO_BIN) get -u -tags ${TAGS}
endif
make test
make install
ifeq ($(GO111MODULE),on)
$(GO_BIN) mod tidy
endif
make tidy

release-test:
$(GO_BIN) test -tags ${TAGS} -race ./...
make tidy

release:
release -y -f version.go
$(GO_BIN) get github.com/gobuffalo/release
make tidy
release -y -f ./cli/version.go --skip-packr
make tidy



66 changes: 66 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
variables:
GOPROXY: "https://proxy.golang.org"
GOBIN: "$(GOPATH)/bin" # Go binaries path
GOPATH: "$(system.defaultWorkingDirectory)/gopath" # Go workspace path
modulePath: "$(GOPATH)/src/github.com/$(build.repository.name)" # Path to the module"s code

jobs:
- job: Windows
pool:
vmImage: "vs2017-win2016"
strategy:
matrix:
go 1.12 (on):
go_version: "1.12.13"
GO111MODULE: "on"
go 1.12 (off):
go_version: "1.12.13"
GO111MODULE: "off"
go 1.13.4 (on):
go_version: "1.13.4"
GO111MODULE: "on"
go 1.13.4 (off):
go_version: "1.13.4"
GO111MODULE: "off"
steps:
- template: azure-tests.yml

- job: macOS
pool:
vmImage: "macOS-10.13"
strategy:
matrix:
go 1.12 (on):
go_version: "1.12.13"
GO111MODULE: "on"
go 1.12 (off):
go_version: "1.12.13"
GO111MODULE: "off"
go 1.13.4 (on):
go_version: "1.13.4"
GO111MODULE: "on"
go 1.13.4 (off):
go_version: "1.13.4"
GO111MODULE: "off"
steps:
- template: azure-tests.yml

- job: Linux
pool:
vmImage: "ubuntu-16.04"
strategy:
matrix:
go 1.12 (on):
go_version: "1.12.13"
GO111MODULE: "on"
go 1.12 (off):
go_version: "1.12.13"
GO111MODULE: "off"
go 1.13.4 (on):
go_version: "1.13.4"
GO111MODULE: "on"
go 1.13.4 (off):
go_version: "1.13.4"
GO111MODULE: "off"
steps:
- template: azure-tests.yml
19 changes: 19 additions & 0 deletions azure-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
steps:
- task: GoTool@0
inputs:
version: $(go_version)
- task: Bash@3
inputs:
targetType: inline
script: |
mkdir -p "$(GOBIN)"
mkdir -p "$(GOPATH)/pkg"
mkdir -p "$(modulePath)"
shopt -s extglob
mv !(gopath) "$(modulePath)"
displayName: "Setup Go Workspace"
- script: |
go get -t -v ./...
go test -race ./...
workingDirectory: "$(modulePath)"
displayName: "Tests"
12 changes: 12 additions & 0 deletions cli/help.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package cli

import (
"context"
"fmt"
)

func Help(ctx context.Context, args []string) error {
stderr := Stderr(ctx)
fmt.Fprintln(stderr, "grift <task name> [task arguments]")
return nil
}
20 changes: 20 additions & 0 deletions cli/help_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cli

import (
"bytes"
"context"
"testing"

"github.com/stretchr/testify/require"
)

func Test_Help(t *testing.T) {
r := require.New(t)

bb := &bytes.Buffer{}

ctx := WithStderr(bb, context.Background())
r.NoError(Help(ctx, []string{}))

r.Contains(bb.String(), "grift <task name> [task arguments]")
}
36 changes: 20 additions & 16 deletions cmd/templates.go → cli/init.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
package cmd
package cli

var modTmpl = `module grifter`

var mainTmpl = `
package main
import (
"context"
"io/ioutil"
"log"
"os"
"path/filepath"
)

import _ "{{.GriftsPackagePath}}"
import "os"
import "log"
import "github.com/markbates/grift/grift"
import "path/filepath"
func Init(ctx context.Context, args []string) error {
pwd, err := os.Getwd()
if err != nil {
return err
}

func main() {
grift.CommandName = "{{.CommandName}}"
if err := os.Chdir(filepath.Dir("{{.GriftsAbsolutePath}}")); err != nil {
log.Fatal(err)
dir := filepath.Join(pwd, "grifts")
if err := os.MkdirAll(dir, 0766); err != nil {
return err
}
err := grift.Exec(os.Args[1:], false)

err = ioutil.WriteFile(filepath.Join(dir, "example.go"), []byte(initTmpl), 0644)
if err != nil {
log.Fatal(err)
}
}`
return nil
}

var initTmpl = `
package grifts
Expand Down
46 changes: 46 additions & 0 deletions cli/io.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package cli

import (
"context"
"io"
"os"
)

const (
stdin = "stdin"
stdout = "stdout"
stderr = "stderr"
)

func WithStdin(r io.Reader, ctx context.Context) context.Context {
return context.WithValue(ctx, stdin, r)
}

func Stdin(ctx context.Context) io.Reader {
if r, ok := ctx.Value(stdin).(io.Reader); ok {
return r
}
return os.Stdin
}

func Stdout(ctx context.Context) io.Writer {
if w, ok := ctx.Value(stdout).(io.Writer); ok {
return w
}
return os.Stdout
}

func Stderr(ctx context.Context) io.Writer {
if w, ok := ctx.Value(stderr).(io.Writer); ok {
return w
}
return os.Stderr
}

func WithStdout(w io.Writer, ctx context.Context) context.Context {
return context.WithValue(ctx, stdout, w)
}

func WithStderr(w io.Writer, ctx context.Context) context.Context {
return context.WithValue(ctx, stderr, w)
}
Loading