Skip to content

Commit

Permalink
- Changes to goreleaser and logging
Browse files Browse the repository at this point in the history
  • Loading branch information
stcrestrada committed May 25, 2024
1 parent cddf390 commit e604886
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 117 deletions.
104 changes: 32 additions & 72 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,90 +1,50 @@
before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
- go generate ./...
project_name: gee

builds:
- id: gee_main_build
- id: gee
main: ./main.go
- env:
- CGO_ENABLED=0
binary: gee
goos:
- linux
- windows
- darwin
goarch:
- amd64
- 386
- arm64
goarm:
- 6
- 7
ldflags:
- -s -w -X main.version={{.Version}}
ignore:
ldflags: -s -w -X main.version={{.Version}}
env:
- CGO_ENABLED=0

archives:
- format_overrides:
- goos: windows
goarch: arm64
format: zip

checksum:
name_template: 'checksums.txt'
name_template: "{{.ProjectName}}_checksums.txt"

snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
name_template: "{{ .Tag }}-SNAPSHOT"

# .goreleaser.yml
brews:
-
# Name template of the recipe
# Default to project name
name: gee

# GOARM to specify which 32-bit arm version to use if there are multiple versions
# from the build section. Brew formulas support atm only one 32-bit version.
# Default is 6 for all artifacts or each id if there a multiple versions.
goarm: 6

# NOTE: make sure the url_template, the token and given repo (github or gitlab) owner and name are from the
# same kind. We will probably unify this in the next major version like it is done with scoop.

# GitHub/GitLab repository to push the formula to
# Gitea is not supported yet, but the support coming
tap:
owner: stcrestrada
name: gee

# Template for the url which is determined by the given Token (github or gitlab)
# Default for github is "https://github.com/<repo_owner>/<repo_name>/releases/download/{{ .Tag }}/{{ .ArtifactName }}"
# Default for gitlab is "https://gitlab.com/<repo_owner>/<repo_name>/-/releases/{{ .Tag }}/downloads/{{ .ArtifactName }}"
# Default for gitea is "https://gitea.com/<repo_owner>/<repo_name>/releases/download/{{ .Tag }}/{{ .ArtifactName }}"
url_template: "https://github.com/stcrestrada/gee/releases/download/{{ .Tag }}/{{ .ArtifactName }}"

# Git author used to commit to the repository.
# Defaults are shown.
commit_author:
name: Stephen Estrada
email: [email protected]

# Your app's homepage.
# Default is empty.
- name: gee
homepage: "https://github.com/stcrestrada/gee"

# Template of your app's description.
# Default is empty.
description: "Manage all your git repos simultaneously."

# SPDX identifier of your app's license.
# Default is empty.
description: "CLI tool that efficiently manages multiple Git repositories simultaneously."
license: "MIT"
url_template: "https://github.com/stcrestrada/gee/releases/download/{{ .Tag }}/{{ .ArtifactName }}"
install: |
bin.install "gee"
test: |
system "#{bin}/gee --version"
changelog:
filters:
exclude:
- "^docs:"
- "^test:"

# Setting this will prevent goreleaser to actually try to commit the updated
# formula - instead, the formula file will be stored on the dist folder only,
# leaving the responsibility of publishing it to the user.
# If set to auto, the release will not be uploaded to the homebrew tap
# in case there is an indicator for prerelease in the tag e.g. v1.0.0-rc1
# Default is false.
skip_upload: false
release:
github:
owner: stcrestrada
name: gee
6 changes: 2 additions & 4 deletions cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
)

type AddCommand struct {
Git *command.GitRepoOperation
Git command.GitRepoOperation
RepoUtils *util.RepoUtils
}

func NewAddCommand() *AddCommand {
repoOp := &command.GitRepoOperation{}
repoOp := command.GitRepoOperation{}
return &AddCommand{
Git: repoOp,
RepoUtils: util.NewRepoUtils(repoOp),
Expand All @@ -35,13 +35,11 @@ func AddCmd() *cli.Command {
func (cmd *AddCommand) Run() error {
cwd, err := cmd.GetWorkingDirectory()
if err != nil {
util.Warning("Warning: %s \n", err)
return err
}

ctx, err := cmd.LoadConfiguration()
if err != nil {
util.Warning("Warning: %s \n", err)
return err
}

Expand Down
7 changes: 3 additions & 4 deletions cmd/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import (
)

type CloneCommand struct {
Git *command.GitRepoOperation
Git command.GitRepoOperation
RepoUtils *util.RepoUtils
}

func NewCloneCommand() *CloneCommand {
repoOp := &command.GitRepoOperation{}
repoOp := command.GitRepoOperation{}
return &CloneCommand{
Git: repoOp,
RepoUtils: util.NewRepoUtils(repoOp),
Expand All @@ -41,8 +41,7 @@ func CloneCmd() *cli.Command {
func (cmd *CloneCommand) Run() error {
ctx, err := cmd.LoadConfiguration()
if err != nil {
util.Warning("Warning: %s \n", err)
return err
return util.NewWarning(err.Error())
}

repos := ctx.Config.Repos
Expand Down
6 changes: 3 additions & 3 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ import (
)

type InitCommand struct {
Git *command.GitRepoOperation
Git command.GitRepoOperation
RepoUtils *util.RepoUtils
}

func NewInitCommand() *InitCommand {
repoOp := &command.GitRepoOperation{}
repoOp := command.GitRepoOperation{}
return &InitCommand{
Git: repoOp,
RepoUtils: util.NewRepoUtils(repoOp),
}
}

func InitCmd() *cli.Command {
initCmd := NewInitCommand()
return &cli.Command{
Name: "init",
Usage: "create gee.toml",
Action: func(context *cli.Context) error {
initCmd := NewInitCommand()
return initCmd.Run()
},
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import (
)

type PullCommand struct {
Git *command.GitRepoOperation
Git command.GitRepoOperation
RepoUtils *util.RepoUtils
}

func NewPullCommand() *PullCommand {
repoOp := &command.GitRepoOperation{}
repoOp := command.GitRepoOperation{}
return &PullCommand{
Git: repoOp,
RepoUtils: util.NewRepoUtils(repoOp),
Expand Down
18 changes: 7 additions & 11 deletions cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import (
)

type StatusCommand struct {
Git *command.GitRepoOperation
Git command.GitRepoOperation
RepoUtils *util.RepoUtils
}

func NewStatusCommand() *StatusCommand {
repoOp := &command.GitRepoOperation{}
repoOp := command.GitRepoOperation{}
return &StatusCommand{
Git: repoOp,
RepoUtils: util.NewRepoUtils(repoOp),
Expand All @@ -40,7 +40,7 @@ func StatusCmd() *cli.Command {
func (cmd *StatusCommand) Run() error {
ctx, err := cmd.LoadConfiguration()
if err != nil {
util.Warning("Warning: %s \n", err)
util.Warning("Warning: %s", err)
return err
}

Expand Down Expand Up @@ -71,15 +71,11 @@ func (cmd *StatusCommand) Run() error {
cmd.Git.Status(repo.Name, fullPath, rc, func(onFinish *types.CommandOnFinish) {
commandOnFinish[i] = onFinish
if !onFinish.Failed {
states[i] = &ui.SpinnerState{
State: ui.StateSuccess,
Msg: fmt.Sprintf("successfully retrieved status for %s", onFinish.Repo),
}
states[i].State = ui.StateSuccess
states[i].Msg = fmt.Sprintf("successfully retrieved status for %s", onFinish.Repo)
} else {
states[i] = &ui.SpinnerState{
State: ui.StateError,
Msg: fmt.Sprintf("failed to pull status for %s", onFinish.Repo),
}
states[i].State = ui.StateError
states[i].Msg = fmt.Sprintf("failed to pull status for %s", onFinish.Repo)
}
})
return nil, nil
Expand Down
10 changes: 8 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@ func main() {
// Run the CLI app
err := app.Run(os.Args)
if err != nil {
util.CheckIfError(err)
return
switch err.(type) {
case *util.InfoError:
util.Info("Information: %s", err.Error())
case *util.WarningError:
util.Warning("Warning: %s", err.Error())
default:
util.CheckIfError(err)
}
}
}

Expand Down
48 changes: 40 additions & 8 deletions pkg/util/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,62 @@ import (
"github.com/fatih/color"
)

// WarningError represents a custom warning error with a message
type WarningError struct {
Message string
}

func (w *WarningError) Error() string {
return w.Message
}

// NewWarning creates a new WarningError
func NewWarning(message string) error {
return &WarningError{Message: message}
}

// InfoError represents a custom info error with a message
type InfoError struct {
Message string
}

func (i *InfoError) Error() string {
return i.Message
}

// NewInfo creates a new InfoError
func NewInfo(message string) error {
return &InfoError{
Message: message,
}
}

// logMessage is a helper function to print messages with specific color attributes
func logMessage(colorAttribute color.Attribute, format string, args ...interface{}) {
c := color.New(colorAttribute, color.Bold)
c.Printf("%s\n", fmt.Sprintf(format, args...))
}

// Info logs an info message with green text and bold style
func Info(format string, args ...interface{}) {
c := color.New(color.FgGreen, color.Bold)
c.Printf("%s\n", fmt.Sprintf(format, args...))
logMessage(color.FgGreen, format, args...)
}

// CheckIfError logs an error message and panics if the error is not nil
func CheckIfError(err error) {
if err == nil {
return
}
c := color.New(color.FgHiRed, color.Bold)
c.Printf("%s\n", fmt.Sprintf("error: %s", err))
logMessage(color.FgHiRed, "error: %s", err)
panic(err)
}

// Warning logs a warning message with yellow text and bold style
func Warning(format string, args ...interface{}) {
c := color.New(color.FgYellow, color.Bold)
c.Printf("%s\n", fmt.Sprintf(format, args...))
logMessage(color.FgYellow, format, args...)
}

// WarningRed logs a warning message with red text and bold style
func WarningRed(format string, args ...interface{}) {
c := color.New(color.FgRed, color.Bold)
c.Printf("%s\n", fmt.Sprintf(format, args...))
logMessage(color.FgRed, format, args...)
}
Loading

0 comments on commit e604886

Please sign in to comment.