Skip to content
This repository was archived by the owner on Jan 4, 2025. It is now read-only.

Commit e046e0e

Browse files
Merge pull request #7 from tadashi-aikawa/0.6.0
0.6.0
2 parents 8bbffd6 + 445721b commit e046e0e

File tree

6 files changed

+61
-5
lines changed

6 files changed

+61
-5
lines changed

Gopkg.lock

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

+4
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,7 @@
5656
[[constraint]]
5757
name = "github.com/briandowns/spinner"
5858
version = "1.2.0"
59+
60+
[[constraint]]
61+
branch = "master"
62+
name = "github.com/mattn/go-pipeline"

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Usage:
3333
gowl edit [-e=<editor> | --editor=<editor>]
3434
gowl web
3535
gowl list
36+
gowl purge
3637
gowl -h | --help
3738
gowl --version
3839

args.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import (
55
"github.com/pkg/errors"
66
)
77

8-
const version = "0.5.2"
8+
const version = "0.6.0"
99
const usage = `Gowl.
1010
1111
Usage:
1212
gowl get [-f | --force] [-r | --recursive] [-s | --shallow] [-B | --bitbucket-server]
1313
gowl edit [-e=<editor> | --editor=<editor>]
1414
gowl web
1515
gowl list
16+
gowl purge
1617
gowl -h | --help
1718
gowl -V | --version
1819
@@ -28,10 +29,11 @@ Options:
2829

2930
// Args created by CLI args
3031
type Args struct {
31-
CmdGet bool `docopt:"get"`
32-
CmdEdit bool `docopt:"edit"`
33-
CmdWeb bool `docopt:"web"`
34-
CmdList bool `docopt:"list"`
32+
CmdGet bool `docopt:"get"`
33+
CmdEdit bool `docopt:"edit"`
34+
CmdWeb bool `docopt:"web"`
35+
CmdList bool `docopt:"list"`
36+
CmdPurge bool `docopt:"purge"`
3537

3638
Editor string `docopt:"--editor"`
3739
Force bool `docopt:"--force"`

command.go

+36
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"time"
1010

1111
"github.com/briandowns/spinner"
12+
"github.com/mattn/go-pipeline"
1213
"github.com/pkg/errors"
1314
survey "gopkg.in/AlecAivazis/survey.v1"
1415
)
@@ -231,6 +232,41 @@ func CmdEdit(handler IHandler, root string, editor string) error {
231232
return nil
232233
}
233234

235+
// CmdPurge purges...
236+
func CmdPurge(handler IHandler, root string) error {
237+
selection, err := selectLocalRepository(root)
238+
if selection == "" {
239+
return nil
240+
}
241+
if err != nil {
242+
return errors.Wrap(err, "Fail to select a repository.")
243+
}
244+
245+
os.Chdir(selection)
246+
247+
branches, err := pipeline.Output(
248+
[]string{"git", "branch", "--merged", "master"},
249+
[]string{"grep", "-vE", "'^\\*|master$|develop$'"},
250+
)
251+
252+
if string(branches) == "" {
253+
print("No branches to purge.")
254+
return nil
255+
}
256+
257+
print("Purge branches...\n" + string(branches))
258+
259+
if _, err := pipeline.Output(
260+
[]string{"git", "branch", "--merged", "master"},
261+
[]string{"grep", "-vE", "'^\\*|master$|develop$'"},
262+
[]string{"xargs", "git", "branch", "-d"},
263+
); err != nil {
264+
return errors.Wrap(err, fmt.Sprintf("Fail to purge repositories %v", selection))
265+
}
266+
267+
return nil
268+
}
269+
234270
// CmdWeb executes `web`
235271
func CmdWeb(handler IHandler, root string, browser string) error {
236272
selection, err := selectLocalRepository(root)

main.go

+4
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,9 @@ func main() {
6464
if err := CmdList(handler, getRoot(config)); err != nil {
6565
log.Fatal(errors.Wrap(err, "Fail to command `list`"))
6666
}
67+
case args.CmdPurge:
68+
if err := CmdPurge(handler, getRoot(config)); err != nil {
69+
log.Fatal(errors.Wrap(err, "Fail to command `purge`"))
70+
}
6771
}
6872
}

0 commit comments

Comments
 (0)