Skip to content

Commit

Permalink
feat: allow to customize branch count by env var
Browse files Browse the repository at this point in the history
  • Loading branch information
Tchoupinax committed Oct 17, 2024
1 parent bff176a commit a54e868
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 10 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ func main() {
cliCommandDisplayHelp(os.Args)

var deleteMode = StringInSlice("-d", os.Args[1:]) || StringInSlice("--delete", os.Args[1:])
var branchCount float64 = 10
if os.Getenv("GIT_BRANCH_COUNT") != "" {
value, err := strconv.Atoi(os.Getenv("GIT_BRANCH_COUNT"))
if err != nil {
CheckIfError(err)
} else {
branchCount = float64(value)
}
}

rootpath := getGitRootPath()

Expand Down Expand Up @@ -97,7 +106,7 @@ func main() {
fmt.Println("")

var count = 1
for branchIndex, branch := range branches[:int(math.Min(float64(len(branches)), 10))] {
for branchIndex, branch := range branches[:int(math.Min(float64(len(branches)), branchCount))] {
var s string
if branch.commitedAt.String() != "0001-01-01 00:00:00 +0000 UTC" {
s = timeago.Of(branch.commitedAt)
Expand Down
4 changes: 4 additions & 0 deletions version.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ func cliCommandDisplayHelp(args []string) {
fmt.Println("build date: ", bold(BuildDate))
fmt.Println("version: ", bold(Version))
fmt.Println()
fmt.Println("-v / --version : display this help menu")
fmt.Println("-d / --delete : enters the delete mode")
// fmt.Println("-c / --count <int>: how many branches to display. Cares about GIT_BRANCH_COUNT")
fmt.Println()
fmt.Println(italic("Need help?"))
fmt.Println(italic("https://github.com/Tchoupinax/git-branch/issues"))
os.Exit(0)
Expand Down

0 comments on commit a54e868

Please sign in to comment.