Skip to content

Commit

Permalink
Merge pull request #10 from thrawn01/thrawn/develop
Browse files Browse the repository at this point in the history
Now using github.com/fatih/color
  • Loading branch information
thrawn01 authored Nov 24, 2021
2 parents bcb669d + f556cdb commit 6816daa
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
6 changes: 5 additions & 1 deletion cmd/clip-remote/clip-remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ import (
"os/exec"
"strings"

"github.com/fatih/color"
"github.com/thrawn01/args"
"github.com/thrawn01/clip"
)

var yellow = color.New(color.FgYellow).PrintfFunc()

func main() {
refs := clip.BranchReferenceMap{}
tracked := clip.TrackedBranchMap{}
Expand Down Expand Up @@ -67,6 +70,7 @@ func main() {
continue
}

// Is this branch name prefixed with something?
if prefix := opts.String("prefix"); prefix != "" {
if !strings.HasPrefix(branch.Name, prefix) {
continue
Expand All @@ -81,7 +85,7 @@ func main() {
}
}

fmt.Printf("\033[33mDeleting %s/%s..\033[0m\n", remote, branch.Name)
yellow("Deleting %s/%s..\n", remote, branch.Name)
// Delete remote branch
if err := exec.Command("git", "push", remote, "--delete", branch.Name).Run(); err != nil {
fmt.Fprintln(os.Stderr, err.Error())
Expand Down
14 changes: 10 additions & 4 deletions cmd/clip/clip.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ package main
import (
"fmt"
"os"

"sort"

"github.com/fatih/color"
"github.com/pkg/errors"
"github.com/thrawn01/clip"
)

var (
yellow = color.New(color.FgYellow).SprintFunc()
red = color.New(color.FgRed).PrintfFunc()
green = color.New(color.FgGreen).PrintfFunc()
)

func aheadBehind(output *string, master, branch string) error {
var ahead, behind []string
if err := clip.CommitsBetween(&ahead, master, branch); err != nil {
Expand Down Expand Up @@ -45,7 +51,7 @@ func printRemotes(branch *clip.BranchDetail) {
os.Exit(1)
}
if len(commits) != 0 {
fmt.Printf("\033[32mis %d commits behind\033[0m\n", len(commits))
green("is %d commits behind\n", len(commits))
continue
}
// Commits Ahead
Expand All @@ -54,7 +60,7 @@ func printRemotes(branch *clip.BranchDetail) {
os.Exit(1)
}
if len(commits) != 0 {
fmt.Printf("\033[31mis %d commits ahead\033[0m\n", len(commits))
red("is %d commits ahead\n", len(commits))
continue
}
fmt.Println("")
Expand Down Expand Up @@ -99,7 +105,7 @@ func main() {
}
}
// Print the branch name and the remote it's tracking
fmt.Printf("\033[33m%s\033[0m%s%s\n", branch.Name, follow, tracked)
fmt.Printf("%s%s%s\n", yellow(branch.Name), follow, tracked)
// Print all the remotes associated with this branch
printRemotes(branch)
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/thrawn01/clip
go 1.10

require (
github.com/fatih/color v1.13.0
github.com/fatih/structs v1.1.0 // indirect
github.com/go-ini/ini v1.42.0 // indirect
github.com/onsi/ginkgo v1.8.0
Expand Down
12 changes: 11 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
Expand All @@ -14,6 +16,11 @@ github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U=
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.8.0 h1:VkHVNpR4iVnU8XQR6DBm8BqYjN7CRzw+xKUbVVbbW9w=
github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
Expand All @@ -40,8 +47,11 @@ golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
Expand Down

0 comments on commit 6816daa

Please sign in to comment.