Skip to content

Commit

Permalink
refactor: formatter to its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
aripalo committed Oct 31, 2021
1 parent f4c3f17 commit 937874f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 28 deletions.
36 changes: 36 additions & 0 deletions internal/logger/format.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package logger

import (
"fmt"

"github.com/aripalo/vegas-credentials/internal/interfaces"
"github.com/gookit/color"
)

// format the log message
func format(a interfaces.AssumeCredentialProcess, colorize color.Color, emoji string, prefix string, message string) string {
f := a.GetFlags()
output := ""

if emoji != "" && !f.NoColor {
output = fmt.Sprintf("%s%s ", output, emoji)
}

if prefix != "" {
var p string
if f.NoColor {
p = fmt.Sprintf("%s:", prefix)
} else {
p = colorize.Render(textBold.Render(fmt.Sprintf("%s:", prefix)))
}
output = fmt.Sprintf("%s%s ", output, p)
}

if f.NoColor {
output = fmt.Sprintf("%s%s", output, message)
} else {
output = fmt.Sprintf("%s%s", output, colorize.Render(message))
}

return output
}
File renamed without changes.
28 changes: 0 additions & 28 deletions internal/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,6 @@ const (
textColorPrompt = color.FgCyan
)

// format the log message
func format(a interfaces.AssumeCredentialProcess, colorize color.Color, emoji string, prefix string, message string) string {
f := a.GetFlags()
output := ""

if emoji != "" && !f.NoColor {
output = fmt.Sprintf("%s%s ", output, emoji)
}

if prefix != "" {
var p string
if f.NoColor {
p = fmt.Sprintf("%s:", prefix)
} else {
p = colorize.Render(textBold.Render(fmt.Sprintf("%s:", prefix)))
}
output = fmt.Sprintf("%s%s ", output, p)
}

if f.NoColor {
output = fmt.Sprintf("%s%s", output, message)
} else {
output = fmt.Sprintf("%s%s", output, colorize.Render(message))
}

return output
}

// Newline prints a newline character
func Newline(a interfaces.AssumeCredentialProcess) {
s := a.GetDestination()
Expand Down

0 comments on commit 937874f

Please sign in to comment.