Skip to content

Commit

Permalink
Merge pull request #7 from tadashi-aikawa/0.6.0
Browse files Browse the repository at this point in the history
0.6.0
  • Loading branch information
tadashi-aikawa committed Dec 4, 2018
2 parents 8bbffd6 + 445721b commit e046e0e
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 5 deletions.
9 changes: 9 additions & 0 deletions Gopkg.lock

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

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,7 @@
[[constraint]]
name = "github.com/briandowns/spinner"
version = "1.2.0"

[[constraint]]
branch = "master"
name = "github.com/mattn/go-pipeline"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Usage:
gowl edit [-e=<editor> | --editor=<editor>]
gowl web
gowl list
gowl purge
gowl -h | --help
gowl --version
Expand Down
12 changes: 7 additions & 5 deletions args.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (
"github.com/pkg/errors"
)

const version = "0.5.2"
const version = "0.6.0"
const usage = `Gowl.
Usage:
gowl get [-f | --force] [-r | --recursive] [-s | --shallow] [-B | --bitbucket-server]
gowl edit [-e=<editor> | --editor=<editor>]
gowl web
gowl list
gowl purge
gowl -h | --help
gowl -V | --version
Expand All @@ -28,10 +29,11 @@ Options:

// Args created by CLI args
type Args struct {
CmdGet bool `docopt:"get"`
CmdEdit bool `docopt:"edit"`
CmdWeb bool `docopt:"web"`
CmdList bool `docopt:"list"`
CmdGet bool `docopt:"get"`
CmdEdit bool `docopt:"edit"`
CmdWeb bool `docopt:"web"`
CmdList bool `docopt:"list"`
CmdPurge bool `docopt:"purge"`

Editor string `docopt:"--editor"`
Force bool `docopt:"--force"`
Expand Down
36 changes: 36 additions & 0 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/briandowns/spinner"
"github.com/mattn/go-pipeline"
"github.com/pkg/errors"
survey "gopkg.in/AlecAivazis/survey.v1"
)
Expand Down Expand Up @@ -231,6 +232,41 @@ func CmdEdit(handler IHandler, root string, editor string) error {
return nil
}

// CmdPurge purges...
func CmdPurge(handler IHandler, root string) error {
selection, err := selectLocalRepository(root)
if selection == "" {
return nil
}
if err != nil {
return errors.Wrap(err, "Fail to select a repository.")
}

os.Chdir(selection)

branches, err := pipeline.Output(
[]string{"git", "branch", "--merged", "master"},
[]string{"grep", "-vE", "'^\\*|master$|develop$'"},
)

if string(branches) == "" {
print("No branches to purge.")
return nil
}

print("Purge branches...\n" + string(branches))

if _, err := pipeline.Output(
[]string{"git", "branch", "--merged", "master"},
[]string{"grep", "-vE", "'^\\*|master$|develop$'"},
[]string{"xargs", "git", "branch", "-d"},
); err != nil {
return errors.Wrap(err, fmt.Sprintf("Fail to purge repositories %v", selection))
}

return nil
}

// CmdWeb executes `web`
func CmdWeb(handler IHandler, root string, browser string) error {
selection, err := selectLocalRepository(root)
Expand Down
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,9 @@ func main() {
if err := CmdList(handler, getRoot(config)); err != nil {
log.Fatal(errors.Wrap(err, "Fail to command `list`"))
}
case args.CmdPurge:
if err := CmdPurge(handler, getRoot(config)); err != nil {
log.Fatal(errors.Wrap(err, "Fail to command `purge`"))
}
}
}

0 comments on commit e046e0e

Please sign in to comment.