Skip to content

Commit

Permalink
feat: colored logging
Browse files Browse the repository at this point in the history
  • Loading branch information
seriouspoop committed Aug 28, 2024
1 parent a9573b6 commit 66aa758
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 7 deletions.
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ require (
github.com/cloudflare/circl v1.3.9 // indirect
github.com/cyphar/filepath-securejoin v0.3.1 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/manifoldco/promptui v0.9.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/skeema/knownhosts v1.3.0 // indirect
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a h1:mATvB/9r/3gvcej
github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM=
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=
github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=
github.com/gliderlabs/ssh v0.3.7 h1:iV3Bqi942d9huXnzEF2Mt+CY9gLu8DNM4Obd+8bODRE=
github.com/gliderlabs/ssh v0.3.7/go.mod h1:zpHEXBstFnQYtGnB8k8kQLol82umzn/2/snG7alWVD8=
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI=
Expand Down Expand Up @@ -58,6 +60,11 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA=
github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI=
github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
Expand Down Expand Up @@ -125,6 +132,7 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
5 changes: 3 additions & 2 deletions internal/handler/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/MakeNowJust/heredoc/v2"
"github.com/seriouspoop/gopush/model"
"github.com/seriouspoop/gopush/svc"
"github.com/seriouspoop/gopush/utils"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -59,7 +60,7 @@ func Run(s servicer) *cobra.Command {
return err
}

fmt.Println("Pulling remote changes...")
utils.Logger(utils.STATUS_INFO, "Pulling remote changes...")
err = s.Pull(false)
if err != nil {
if errors.Is(err, svc.ErrAuthNotFound) {
Expand All @@ -70,7 +71,7 @@ func Run(s servicer) *cobra.Command {
}
return err
}
fmt.Println("✅ changes fetched.")
utils.Logger(utils.STATUS_SUCCESS, "changes fetched")
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import "github.com/seriouspoop/gopush/internal"
import (
"github.com/seriouspoop/gopush/internal"
)

func main() {
root, err := internal.NewRoot()
Expand Down
10 changes: 6 additions & 4 deletions svc/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/manifoldco/promptui"
"github.com/seriouspoop/gopush/model"
"github.com/seriouspoop/gopush/utils"
)

func (s *Svc) LoadProject() error {
Expand All @@ -31,7 +32,8 @@ func (s *Svc) InitializeRepo() error {
if err != nil {
return err
}
fmt.Println("✅ Repository initialized.")

utils.Logger(utils.STATUS_SUCCESS, "Repository initialized")
return nil
}

Expand All @@ -55,7 +57,7 @@ func (s *Svc) InitializeRemote() error {
if err != nil {
return err
}
fmt.Println(" Remote added.")
fmt.Println("\U00002714 Remote added.")
return nil
}

Expand Down Expand Up @@ -154,7 +156,7 @@ func (s *Svc) StageChanges() error {
if err != nil {
return err
}
fmt.Println("✅ Files added.")
utils.Logger(utils.STATUS_SUCCESS, "Files added")
}
return nil
}
Expand Down Expand Up @@ -187,6 +189,6 @@ func (s *Svc) Push(setUpstreamBranch bool) (output string, err error) {
return "", err
}
}
fmt.Println("✅ Push Successful.")
utils.Logger(utils.STATUS_SUCCESS, "Push Successful")
return
}
30 changes: 30 additions & 0 deletions utils/logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package utils

import (
"fmt"

"github.com/fatih/color"
)

// terminal colors
var green = color.New(color.FgGreen).SprintFunc()
var red = color.New(color.FgHiRed).SprintFunc()

type status int

const (
STATUS_UNKNOWN status = iota
STATUS_INFO
STATUS_SUCCESS
STATUS_FAILURE
)

func Logger(s status, log string) {
statusToUnicode := map[status]string{
STATUS_INFO: "",
STATUS_SUCCESS: green("\U00002714 "),
STATUS_FAILURE: red("\U00002717 "),
}

fmt.Printf("%s%s\n", statusToUnicode[s], log)
}

0 comments on commit 66aa758

Please sign in to comment.