Skip to content

Commit

Permalink
Add initOnce / init in renderer to handle when not yet initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
cyx committed Sep 5, 2020
1 parent 977e9ce commit a82d0c4
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions internal/display/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package display
import (
"fmt"
"io"
"os"
"strings"
"sync"

"github.com/auth0/auth0-cli/internal/ansi"
"github.com/cyx/auth0/management"
Expand All @@ -14,19 +16,35 @@ type Renderer struct {
Tenant string

Writer io.Writer

initOnce sync.Once
}

func (r *Renderer) init() {
r.initOnce.Do(func() {
if r.Writer == nil {
r.Writer = os.Stdout
}
})
}

func (r *Renderer) Infof(format string, a ...interface{}) {
r.init()

fmt.Fprint(r.Writer, aurora.Green(" ▸ "))
fmt.Fprintf(r.Writer, format+"\n", a...)
}

func (r *Renderer) Warnf(format string, a ...interface{}) {
r.init()

fmt.Fprint(r.Writer, aurora.Yellow(" ▸ "))
fmt.Fprintf(r.Writer, format+"\n", a...)
}

func (r *Renderer) Errorf(format string, a ...interface{}) {
r.init()

fmt.Fprint(r.Writer, aurora.BrightRed(" ▸ "))
fmt.Fprintf(r.Writer, format+"\n", a...)
}
Expand Down

0 comments on commit a82d0c4

Please sign in to comment.