Skip to content

Commit

Permalink
DRY
Browse files Browse the repository at this point in the history
  • Loading branch information
coilysiren committed Aug 24, 2019
1 parent 8469a9d commit 29ad6ee
Showing 1 changed file with 13 additions and 51 deletions.
64 changes: 13 additions & 51 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ func main() {
}
}

func VetActionFunc(_ *cli.Context) error {
cmd := exec.Command("go", "vet")
func runCmd(args ...string) error {
cmd := exec.Command(args[0], args[1:]...)

cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
Expand All @@ -62,6 +62,10 @@ func VetActionFunc(_ *cli.Context) error {
return cmd.Run()
}

func VetActionFunc(_ *cli.Context) error {
return runCmd("go", "vet")
}

func TestActionFunc(c *cli.Context) error {
for _, pkg := range packages {
var packageName string
Expand All @@ -74,13 +78,7 @@ func TestActionFunc(c *cli.Context) error {

coverProfile := fmt.Sprintf("--coverprofile=%s.coverprofile", pkg)

cmd := exec.Command("go", "test", "-v", coverProfile, packageName)

cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

err := cmd.Run()
err := runCmd("go", "test", "-v", coverProfile, packageName)
if err != nil {
return err
}
Expand Down Expand Up @@ -152,34 +150,16 @@ func GfmrunActionFunc(_ *cli.Context) error {
return err
}

cmd := exec.Command("gfmrun", "-c", fmt.Sprint(counter), "-s", "README.md")

cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

return cmd.Run()
return runCmd("gfmrun", "-c", fmt.Sprint(counter), "-s", "README.md")
}

func TocActionFunc(_ *cli.Context) error {
cmd := exec.Command("node_modules/.bin/markdown-toc", "-i", "README.md")

cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

err := cmd.Run()
err := runCmd("node_modules/.bin/markdown-toc", "-i", "README.md")
if err != nil {
return err
}

cmd = exec.Command("git", "diff", "--exit-code")

cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

err = cmd.Run()
err = runCmd("git", "diff", "--exit-code")
if err != nil {
return err
}
Expand All @@ -188,35 +168,17 @@ func TocActionFunc(_ *cli.Context) error {
}

func GenActionFunc(_ *cli.Context) error {
cmd := exec.Command("go", "generate", "flag-gen/main.go")

cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

err := cmd.Run()
err := runCmd("go", "generate", "flag-gen/main.go")
if err != nil {
return err
}

cmd = exec.Command("go", "generate", "cli.go")

cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

err = cmd.Run()
err = runCmd("go", "generate", "cli.go")
if err != nil {
return err
}

cmd = exec.Command("git", "diff", "--exit-code")

cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

err = cmd.Run()
err = runCmd("git", "diff", "--exit-code")
if err != nil {
return err
}
Expand Down

0 comments on commit 29ad6ee

Please sign in to comment.