Skip to content

Commit

Permalink
Add warning log
Browse files Browse the repository at this point in the history
  • Loading branch information
maidul98 committed Jan 10, 2023
1 parent 12e104e commit b702f29
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions cli/packages/util/log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package util

import (
"fmt"
"os"

"github.com/fatih/color"
)

func HandleError(err error, messages ...string) {
PrintErrorAndExit(1, err, messages...)
}

func PrintErrorAndExit(exitCode int, err error, messages ...string) {
printError(err)

if len(messages) > 0 {
for _, message := range messages {
fmt.Println(message)
}
}

os.Exit(exitCode)
}

func PrintWarning(message string) {
color.Yellow("Warning: %v", message)
}

func PrintMessageAndExit(messages ...string) {
if len(messages) > 0 {
for _, message := range messages {
fmt.Println(message)
}
}

os.Exit(1)
}

func printError(e error) {
color.Red("Hmm, we ran into an error: %v", e)
}

0 comments on commit b702f29

Please sign in to comment.