Skip to content

Commit

Permalink
fix bitcomplete printing debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswalz committed Oct 19, 2020
1 parent c63fae8 commit b8ffe3c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
5 changes: 5 additions & 0 deletions bitcomplete/complete.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"github.com/chriswalz/bit/cmd"
"github.com/posener/complete/v2"
"github.com/posener/complete/v2/predict"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/thoas/go-funk"
"os"
"strconv"
Expand All @@ -19,6 +21,9 @@ func main() {
doInstall := os.Getenv("COMP_INSTALL") == "1"
doUninstall := os.Getenv("COMP_UNINSTALL") == "1"

log.Logger = log.With().Caller().Logger().Output(zerolog.ConsoleWriter{Out: os.Stderr})
zerolog.SetGlobalLevel(zerolog.InfoLevel)

if !doInstall && !doUninstall {
i, err := strconv.Atoi(compPoint)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/rootShell.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
var ShellCmd = &cobra.Command{
Use: "bit",
Short: "Bit is a Git CLI that predicts what you want to do",
Long: `v0.6.11`,
Long: `v0.6.14`,
Run: func(cmd *cobra.Command, args []string) {
completerSuggestionMap, bitCmdMap := CreateSuggestionMap(cmd)

Expand Down Expand Up @@ -141,7 +141,7 @@ func GitCommandsPromptUsed(args []string, suggestionMap map[string][]prompt.Sugg
// expected usage format
// bit (checkout|switch|co) [-b] branch-name
if args[len(args)-1] == "--version" {
log.Debug().Msg("bit version v0.6.11")
fmt.Println("bit version v0.6.14")
}
if isBranchCompletionCommand(sub) {
branchName := ""
Expand Down
11 changes: 9 additions & 2 deletions cmd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func HandleExit() {
fmt.Println(v)
fmt.Println(string(debug.Stack()))
fmt.Println("OS:", runtime.GOOS, runtime.GOARCH)
fmt.Println("bit version v0.6.11")
fmt.Println("bit version v0.6.14")
PrintGitVersion()

}
Expand Down Expand Up @@ -404,4 +404,11 @@ func isBranchCompletionCommand(command string) bool {
return command == "checkout" || command == "switch" || command == "co" || command == "merge"
}


func Find(slice []string, val string) int {
for i, item := range slice {
if item == val {
return i
}
}
return -1
}
18 changes: 6 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,25 @@ import (
"os"
)

func find(slice []string, val string) int {
for i, item := range slice {
if item == val {
return i
}
}
return -1
}

func main() {
// defer needed to handle funkyness with CTRL + C & go-prompt
defer bitcmd.HandleExit()

// set debug level
log.Logger = log.With().Caller().Logger().Output(zerolog.ConsoleWriter{Out: os.Stderr})
argsWithoutProg := os.Args[1:]

zerolog.SetGlobalLevel(zerolog.InfoLevel)
debugIndex := find(argsWithoutProg, "--debug")
debugIndex := bitcmd.Find(argsWithoutProg, "--debug")
if debugIndex != -1 {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
argsWithoutProg = append(argsWithoutProg[:debugIndex], argsWithoutProg[debugIndex+1:]...)
}

// verify is git repo
if !bitcmd.IsGitRepo() {
if len(os.Args) == 2 && os.Args[1] == "--version" {
fmt.Println("bit version v0.6.11")
fmt.Println("bit version v0.6.14")
bitcmd.PrintGitVersion()
return
}
Expand All @@ -56,7 +50,7 @@ func main() {
}

bitcliCmds := []string{"save", "sync", "version", "help", "info", "release"}
if len(argsWithoutProg) == 0 || find(bitcliCmds, argsWithoutProg[0]) != -1 {
if len(argsWithoutProg) == 0 || bitcmd.Find(bitcliCmds, argsWithoutProg[0]) != -1 {
bitcli()
} else {
completerSuggestionMap, _ := bitcmd.CreateSuggestionMap(bitcmd.ShellCmd)
Expand Down

0 comments on commit b8ffe3c

Please sign in to comment.