Skip to content

Commit

Permalink
Reorganizing code
Browse files Browse the repository at this point in the history
  • Loading branch information
willvedd committed Jan 9, 2023
1 parent 59ae843 commit d0801f2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
5 changes: 2 additions & 3 deletions internal/cli/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ func listLogsCmd(cli *cli) *cobra.Command {
return fmt.Errorf("An unexpected error occurred while getting logs: %v", err)
}

var logsCh chan []*management.Log
cli.renderer.LogList(list, logsCh, !cli.debug)
cli.renderer.LogList(list, !cli.debug)
return nil
},
}
Expand Down Expand Up @@ -154,7 +153,7 @@ func tailLogsCmd(cli *cli) *cobra.Command {
}
}()

cli.renderer.LogList(list, logsCh, !cli.debug)
cli.renderer.LogsTail(list, logsCh, !cli.debug)
return nil
},
}
Expand Down
39 changes: 26 additions & 13 deletions internal/display/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (v *logView) typeDesc() (typ, desc string) {
return typ, desc
}

func (r *Renderer) LogList(logs []*management.Log, ch <-chan []*management.Log, silent bool) {
func (r *Renderer) LogsTail(logs []*management.Log, ch <-chan []*management.Log, silent bool) {
resource := "logs"

r.Heading(resource)
Expand All @@ -160,22 +160,35 @@ func (r *Renderer) LogList(logs []*management.Log, ch <-chan []*management.Log,
res = append(res, &logView{Log: l, silent: silent, raw: l})
}

var viewChan chan View
var viewChan = make(chan View)

if ch != nil {
viewChan = make(chan View)
go func() {
defer close(viewChan)

go func() {
defer close(viewChan)

for list := range ch {
for _, l := range list {
viewChan <- &logView{Log: l, silent: silent, raw: l}
}
for list := range ch {
for _, l := range list {
viewChan <- &logView{Log: l, silent: silent, raw: l}
}
}()
}
}()

r.Stream(res, viewChan) // streams results for `auth0 logs tail`
r.Stream(res, viewChan)
}

func (r *Renderer) LogList(logs []*management.Log, silent bool) {
resource := "logs"

r.Heading(resource)

if len(logs) == 0 {
r.EmptyState(resource)
r.Infof("To generate logs, run a test command like 'auth0 test login' or 'auth0 test token'")
return
}

var res []View
for _, l := range logs {
res = append(res, &logView{Log: l, silent: silent, raw: l})
}

r.Results(res) //Includes headers for `auth0 logs list`
Expand Down

0 comments on commit d0801f2

Please sign in to comment.