Skip to content

Commit

Permalink
update deps for retry tool
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilsk committed Jan 10, 2019
1 parent 7ece618 commit 42a36ac
Show file tree
Hide file tree
Showing 142 changed files with 24,432 additions and 4,460 deletions.
13 changes: 7 additions & 6 deletions cmd/generate/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
"text/template"
)

//go:generate go run gen.go -output parser_gen.go
//go:generate gofmt -w parser_gen.go
//go:generate go run gen.go -output ../retry/parser_gen.go
//go:generate goimports -ungroup -w ../retry/parser_gen.go

const tpl = `
{{ if .BuildTags }}// +build{{ range .BuildTags }} {{ . }}{{ end }}{{ end }}
{{ if .BuildTags }}//+build{{ range .BuildTags }} {{ . }}{{ end }}{{ end }}
package main
Expand Down Expand Up @@ -312,15 +312,16 @@ func generatedNormalDistributionTransformation(raw string) (jitter.Transformatio
var output = flag.String("output", "parser_gen.go", "output filename")

func main() {
flag.Parse()
t := template.Must(template.New("parser").Parse(tpl))
f, err := os.Create(*output)
if err != nil {
panic(err)
}
defer f.Close()
t.Execute(f, struct {
defer func () { _ = f.Close() }()
_ = t.Execute(f, struct {
BuildTags []string
}{
BuildTags: []string{"go1.10"},
BuildTags: []string{"go1.11"},
})
}
16 changes: 8 additions & 8 deletions cmd/retry/Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions cmd/retry/Gopkg.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
[[constraint]]
name = "github.com/briandowns/spinner"
version = "^1.0.0"
version = "1.4.0"

[[constraint]]
name = "github.com/fatih/color"
version = "^1.5.0"
version = "1.7.0"

[[constraint]]
name = "github.com/kamilsk/go-kit"
branch = "master"

[[override]]
name = "github.com/pkg/errors"
version = "^0.8.0"
version = "0.8.1"

[[constraint]]
name = "github.com/spf13/cobra"
version = "^0.0.3"
version = "0.0.3"

[[constraint]]
name = "github.com/stretchr/testify"
version = "^1.1.4"
version = "1.3.0"

[prune]
go-tests = true
Expand Down
9 changes: 4 additions & 5 deletions cmd/retry/completion.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build go1.10
//+build go1.11

package main

Expand All @@ -12,8 +12,7 @@ const (
zshFormat = "zsh"
)

// Completion prints Bash or Zsh completion.
var Completion = &cobra.Command{
var completionCommand = &cobra.Command{
Use: "completion",
Short: "Print Bash or Zsh completion",
RunE: func(cmd *cobra.Command, args []string) error {
Expand All @@ -32,6 +31,6 @@ var Completion = &cobra.Command{
}

func init() {
Completion.Flags().StringVarP(new(string), "format", "f", zshFormat, "output format, one of: bash|zsh")
fn.Must(func() error { return Completion.MarkFlagRequired("format") })
completionCommand.Flags().StringVarP(new(string), "format", "f", zshFormat, "output format, one of: bash|zsh")
fn.Must(func() error { return completionCommand.MarkFlagRequired("format") })
}
12 changes: 6 additions & 6 deletions cmd/retry/completion_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build go1.10
//+build go1.11

package main

Expand All @@ -11,12 +11,12 @@ import (
)

func TestCompletion(t *testing.T) {
before := Completion.OutOrStdout()
defer Completion.SetOutput(before)
before := completionCommand.OutOrStdout()
defer completionCommand.SetOutput(before)

buf := bytes.NewBuffer(nil)
cmd := &cobra.Command{Use: "test"}
cmd.AddCommand(Completion)
cmd.AddCommand(completionCommand)
cmd.SetOutput(buf)

tests := []struct {
Expand All @@ -31,8 +31,8 @@ func TestCompletion(t *testing.T) {
tc := test
t.Run(test.name, func(t *testing.T) {
buf.Reset()
Completion.Flag("format").Value.Set(tc.format)
assert.NoError(t, Completion.RunE(Completion, nil))
assert.NoError(t, completionCommand.Flag("format").Value.Set(tc.format))
assert.NoError(t, completionCommand.RunE(completionCommand, nil))
assert.Contains(t, buf.String(), tc.expected)
})
}
Expand Down
25 changes: 12 additions & 13 deletions cmd/retry/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build go1.10
//+build go1.11

package main

Expand All @@ -24,8 +24,7 @@ const (
failed = 1
)

// DefaultReport is a default template for report.
var DefaultReport = `
var reportTpl = `
---
Expand All @@ -41,16 +40,16 @@ details: started at {{ .Start }}, finished at {{ .End }}, elapsed {{ .Elapsed }}
{{ .Stderr }}
`

func main() { application{Args: os.Args, Stderr: os.Stderr, Stdout: os.Stdout, Shutdown: os.Exit}.Run() }
func main() { tool{Args: os.Args, Stderr: os.Stderr, Stdout: os.Stdout, Shutdown: os.Exit}.Run() }

type application struct {
type tool struct {
Args []string
Stderr, Stdout io.Writer
Shutdown func(code int)
}

// Run executes the application logic.
func (app application) Run() {
// Run executes the tool logic.
func (app tool) Run() {
var (
result, err = parse(app.Stderr, app.Args[0], app.Args[1:]...)
format = func() string {
Expand All @@ -62,11 +61,11 @@ func (app application) Run() {
start, finish time.Time
shutdown, spin = app.Shutdown, spinner.New(spinner.CharSets[17], 100*time.Millisecond)
stderr, stdout = bytes.NewBuffer(nil), bytes.NewBuffer(nil)
report = template.Must(template.New("report").Parse(DefaultReport))
report = template.Must(template.New("report").Parse(reportTpl))
)
if err != nil {
if err != flag.ErrHelp {
color.New(color.FgRed).Fprintf(app.Stderr, format, err)
_, _ = color.New(color.FgRed).Fprintf(app.Stderr, format, err)
app.Shutdown(failed)
return
}
Expand All @@ -87,9 +86,9 @@ func (app application) Run() {
// TODO try to find or implement by myself
// - https://github.com/variadico/noti
// - https://github.com/jolicode/JoliNotif
color.New(color.FgYellow).Fprintln(stderr, "notify component is not ready yet")
_, _ = color.New(color.FgYellow).Fprintln(stderr, "notify component is not ready yet")
}
report.Execute(app.Stdout, struct {
_ = report.Execute(app.Stdout, struct {
Name string
Error string
Start, End string
Expand All @@ -115,8 +114,8 @@ func (app application) Run() {
spin.Start()
start = time.Now()
} else {
spin.Color("red")
color.New(color.FgYellow).Fprintf(stderr, "#%d attempt at %s... \n", attempt+1, time.Now().Sub(start))
_ = spin.Color("red")
_, _ = color.New(color.FgYellow).Fprintf(stderr, "#%d attempt at %s... \n", attempt+1, time.Now().Sub(start))
}
cmd := exec.Command(result.Args[0], result.Args[1:]...)
cmd.Stderr, cmd.Stdout = stderr, stdout
Expand Down
4 changes: 2 additions & 2 deletions cmd/retry/main_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build go1.10
//+build go1.11

package main

Expand All @@ -11,7 +11,7 @@ import (

func TestMain_Exec_Fails(t *testing.T) {
var status int
application{
tool{
Args: []string{"cmd", "unknown"},
Stderr: ioutil.Discard, Stdout: ioutil.Discard,
Shutdown: func(code int) { status = code },
Expand Down
4 changes: 2 additions & 2 deletions cmd/retry/parser.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build go1.10
//+build go1.11

package main

Expand Down Expand Up @@ -33,7 +33,7 @@ type Command struct {
}

var (
re = regexp.MustCompile(`^(\w+)(?::((?:[\w\.]+,?)+))?$`)
re = regexp.MustCompile(`^(\w+)(?::((?:[\w.]+,?)+))?$`)

compliance map[string]struct {
cursor interface{}
Expand Down
4 changes: 2 additions & 2 deletions cmd/retry/parser_gen.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build go1.10
//+build go1.11

package main

Expand Down Expand Up @@ -55,7 +55,7 @@ func init() {
}
usage = func(output io.Writer, md Metadata) func() {
return func() {
fmt.Fprintf(output, `
_, _ = fmt.Fprintf(output, `
Usage: %s [-timeout Timeout] [--debug] [--notify] [strategy flags] -- command
The strategy flags
Expand Down
2 changes: 1 addition & 1 deletion cmd/retry/parser_gen_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build go1.10
//+build go1.11

package main

Expand Down
2 changes: 1 addition & 1 deletion cmd/retry/parser_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build go1.10
//+build go1.11

package main

Expand Down
Loading

0 comments on commit 42a36ac

Please sign in to comment.