Skip to content

Commit 6521f9c

Browse files
duedares-rvjkushalshit27dependabot[bot]ramya18101
authored
Improved support for visualizing logs (#1195)
* v1 * final updates * comments * Added tenant acl ea support (#1166) * Add Network ACL commands * Update network ACL command --no-input * Enhance network ACL update command to support match and not match criteria with user prompts * Enhance interactive update flow for network ACL to allow selective field updates * Fix default scope assignment in network ACL update to allow empty scope * Add network ACL resource fetcher to support fetching network ACL data * Add mock implementation for NetworkACLAPI and corresponding tests * mockgen file created * Add match/not match rule selection to network ACL command * Add integration tests for network ACL commands and a script to fetch ACL IDs * Make docs * lint fix * Enhance help messages for network ACL flags with usage examples * Enhance doc * integartion tes: network ACLs * update to go-auth0 v1.18.1-0.20250326075009-e865086539dc * fix: go.sum * Update go-auth0 v1.19.0 * fix: update go-auth0 to v1.19.0 * fix: update JSON key for IPv4 CIDR in network ACL examples * fix: comment out network ACL test cases in YAML file * fix: update IPv4 CIDR key in network ACL commands and modify test cases * fix: update network ACL test cases for improved clarity and modify priority settings * fix: update test case numbers in network ACL YAML file for consistency * fix: remove anonymous proxy handling from network ACL commands and display * fix: remove anonymous proxy handling from network ACL create and update documentation * fix: update network ACL test cases for consistency and clarity * fix: update event stream test cases to reflect enabled status * fix: update network ACL test cases for geo_country_codes and improve output consistency * fix: update network ACL commands to use geo_country_codes instead of country_codes * fix: update description in network ACL creation test case for consistency * fix: comment out the create network ACL test case for clarity * fix: update network ACL test cases for consistency and correct ipv4_cidrs usage * fix: restore and update create network ACL test case for clarity and output validation * fix: update network ACL test cases and documentation to use consistent ipv4_cidrs notation * fix: refactor network ACL view to improve data handling and display consistency * fix: update examples in network ACL create and update documentation for accuracy * fix: update network ACL test cases for priority adjustments and output validation * fix: improve comments for clarity in network ACL management code * fix: enhance comments for consistency in network ACL management code * fix: standardize description in network ACL test case for consistency * fix: update network ACL test cases to include ID and improve output consistency * fix: remove ID check from network ACL test case output validation * fix: update network ACL test case to include active status in output validation * fix remove DESCRIPTION * fix: add interval configuration and update output validation to include DESCRIPTION in network ACL test case * fix: remove unused AskIntSliceU and RegisterIntSliceU functions from flags.go * fix: update help messages to indicate required fields and default values in network ACL configuration * fix: implement parameter selection for network ACL configuration * fix: enhance parameter selection for network ACL configuration with formatted values * fix: clean up comments and formatting in network ACL configuration * lint fix * Update network ACL help text and improve priority validation error message * test: add unit tests for network ACL resource fetcher * refactor: simplify parameter selection for network ACL configuration * refactor: improve prompt messages for match criteria updates in network ACL * Bump golang.org/x/text from 0.23.0 to 0.24.0 (#1193) Bumps [golang.org/x/text](https://github.com/golang/text) from 0.23.0 to 0.24.0. - [Release notes](https://github.com/golang/text/releases) - [Commits](golang/text@v0.23.0...v0.24.0) --- updated-dependencies: - dependency-name: golang.org/x/text dependency-version: 0.24.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Ramya Anusri <[email protected]> * Bump golang.org/x/net from 0.38.0 to 0.39.0 (#1190) Bumps [golang.org/x/net](https://github.com/golang/net) from 0.38.0 to 0.39.0. - [Commits](golang/net@v0.38.0...v0.39.0) --- updated-dependencies: - dependency-name: golang.org/x/net dependency-version: 0.39.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump github.com/getsentry/sentry-go from 0.31.1 to 0.32.0 (#1191) Bumps [github.com/getsentry/sentry-go](https://github.com/getsentry/sentry-go) from 0.31.1 to 0.32.0. - [Release notes](https://github.com/getsentry/sentry-go/releases) - [Changelog](https://github.com/getsentry/sentry-go/blob/master/CHANGELOG.md) - [Commits](getsentry/sentry-go@v0.31.1...v0.32.0) --- updated-dependencies: - dependency-name: github.com/getsentry/sentry-go dependency-version: 0.32.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Ramya Anusri <[email protected]> * Bump nokogiri from 1.18.4 to 1.18.8 in /docs (#1186) Bumps [nokogiri](https://github.com/sparklemotion/nokogiri) from 1.18.4 to 1.18.8. - [Release notes](https://github.com/sparklemotion/nokogiri/releases) - [Changelog](https://github.com/sparklemotion/nokogiri/blob/main/CHANGELOG.md) - [Commits](sparklemotion/nokogiri@v1.18.4...v1.18.8) --- updated-dependencies: - dependency-name: nokogiri dependency-version: 1.18.8 dependency-type: indirect ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Ramya Anusri <[email protected]> * Bump github.com/charmbracelet/glamour from 0.8.0 to 0.10.0 (#1189) Bumps [github.com/charmbracelet/glamour](https://github.com/charmbracelet/glamour) from 0.8.0 to 0.10.0. - [Release notes](https://github.com/charmbracelet/glamour/releases) - [Changelog](https://github.com/charmbracelet/glamour/blob/master/.goreleaser.yml) - [Commits](charmbracelet/glamour@v0.8.0...v0.10.0) --- updated-dependencies: - dependency-name: github.com/charmbracelet/glamour dependency-version: 0.10.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Ramya Anusri <[email protected]> * Add change log for v1.12.0 (#1194) * Add change log for v1.12.0 * Update change log for v1.12.0 * rebased main * updated go sum * lint * lint * Final changes * lint and go mod * minor refactor * updated lint * lint fix * FINAL LINT --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Kushal <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Ramya Anusri <[email protected]>
1 parent 4754db4 commit 6521f9c

File tree

6 files changed

+180
-18
lines changed

6 files changed

+180
-18
lines changed

docs/auth0_logs_list.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ auth0 logs list [flags]
3535
-f, --filter string Filter in Lucene query syntax. See https://auth0.com/docs/logs/log-search-query-syntax for more details.
3636
--json Output in json format.
3737
-n, --number int Number of log entries to show. Minimum 1, maximum 1000. (default 100)
38+
-p, --picker Allows to toggle from list of logs and view a selected log in detail
3839
```
3940

4041

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ require (
1212
github.com/auth0/go-auth0 v1.20.0
1313
github.com/briandowns/spinner v1.23.2
1414
github.com/charmbracelet/glamour v0.10.0
15+
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e
1516
github.com/fsnotify/fsnotify v1.9.0
1617
github.com/getsentry/sentry-go v0.32.0
1718
github.com/golang/mock v1.6.0
@@ -24,7 +25,9 @@ require (
2425
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
2526
github.com/lestrrat-go/jwx v1.2.30
2627
github.com/logrusorgru/aurora v2.0.3+incompatible
28+
github.com/manifoldco/promptui v0.9.0
2729
github.com/mattn/go-isatty v0.0.20
30+
github.com/mattn/go-tty v0.0.7
2831
github.com/mholt/archiver/v3 v3.5.1
2932
github.com/olekukonko/tablewriter v0.0.5
3033
github.com/pkg/browser v0.0.0-20210706143420-7d21f8c997e2

go.sum

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQ
5959
github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
6060
github.com/chengxilo/virtualterm v1.0.4 h1:Z6IpERbRVlfB8WkOmtbHiDbBANU7cimRIof7mk9/PwM=
6161
github.com/chengxilo/virtualterm v1.0.4/go.mod h1:DyxxBZz/x1iqJjFxTFcr6/x+jSpqN0iwWCOK1q10rlY=
62+
github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE=
63+
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
64+
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8=
65+
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
66+
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8=
67+
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
6268
github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU=
6369
github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA=
6470
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
@@ -178,6 +184,8 @@ github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczG
178184
github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
179185
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
180186
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
187+
github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA=
188+
github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg=
181189
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
182190
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
183191
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
@@ -189,6 +197,8 @@ github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m
189197
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
190198
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
191199
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
200+
github.com/mattn/go-tty v0.0.7 h1:KJ486B6qI8+wBO7kQxYgmmEFDaFEE96JMBQ7h400N8Q=
201+
github.com/mattn/go-tty v0.0.7/go.mod h1:f2i5ZOvXBU/tCABmLmOfzLz9azMo5wdAaElRNnJKr+k=
192202
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
193203
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI=
194204
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
@@ -295,6 +305,7 @@ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJ
295305
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
296306
golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610=
297307
golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
308+
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
298309
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
299310
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
300311
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

internal/cli/logs.go

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"sort"
66
"time"
77

8+
"github.com/auth0/auth0-cli/internal/auth0"
9+
810
"github.com/auth0/go-auth0/management"
911
"github.com/spf13/cobra"
1012
"golang.org/x/net/context"
@@ -29,6 +31,13 @@ var (
2931
ShortForm: "n",
3032
Help: "Number of log entries to show. Minimum 1, maximum 1000.",
3133
}
34+
35+
enableLogPicker = Flag{
36+
Name: "Interactive picker option on rendered logs",
37+
LongForm: "picker",
38+
ShortForm: "p",
39+
Help: "Allows to toggle from list of logs and view a selected log in detail",
40+
}
3241
)
3342

3443
func logsCmd(cli *cli) *cobra.Command {
@@ -50,6 +59,7 @@ func listLogsCmd(cli *cli) *cobra.Command {
5059
var inputs struct {
5160
Filter string
5261
Num int
62+
Picker bool
5363
}
5464

5565
cmd := &cobra.Command{
@@ -72,19 +82,43 @@ func listLogsCmd(cli *cli) *cobra.Command {
7282
if inputs.Num < 1 || inputs.Num > 1000 {
7383
return fmt.Errorf("number flag invalid, please pass a number between 1 and 1000")
7484
}
75-
list, err := getLatestLogs(cmd.Context(), cli, inputs.Num, inputs.Filter)
85+
logs, err := getLatestLogs(cmd.Context(), cli, inputs.Num, inputs.Filter)
7686
if err != nil {
7787
return fmt.Errorf("failed to list logs: %w", err)
7888
}
7989

8090
hasFilter := inputs.Filter != ""
81-
cli.renderer.LogList(list, !cli.debug, hasFilter)
91+
if !inputs.Picker {
92+
cli.renderer.LogList(logs, !cli.debug, hasFilter)
93+
} else {
94+
var (
95+
selectedLogID string
96+
currentIndex = auth0.Int(0)
97+
)
98+
for {
99+
selectedLogID = cli.renderer.LogPrompt(logs, hasFilter, currentIndex)
100+
101+
logDetail, err := cli.api.Log.Read(cmd.Context(), selectedLogID)
102+
if err != nil {
103+
fmt.Println("Failed to fetch details:", err)
104+
continue
105+
}
106+
107+
fmt.Println("\nDetailed Log:")
108+
cli.renderer.JSONResult(logDetail)
109+
110+
if cli.renderer.QuitPrompt() {
111+
break
112+
}
113+
}
114+
}
82115
return nil
83116
},
84117
}
85118

86119
logsFilter.RegisterString(cmd, &inputs.Filter, "")
87120
logsNum.RegisterInt(cmd, &inputs.Num, defaultPageSize)
121+
enableLogPicker.RegisterBool(cmd, &inputs.Picker, false)
88122

89123
cmd.Flags().BoolVar(&cli.json, "json", false, "Output in json format.")
90124
cmd.Flags().BoolVar(&cli.csv, "csv", false, "Output in csv format.")

internal/display/logs.go

Lines changed: 127 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ import (
44
"fmt"
55
"strings"
66

7+
"github.com/auth0/go-auth0/management"
8+
79
"github.com/auth0/auth0-cli/internal/ansi"
810
"github.com/auth0/auth0-cli/internal/auth0"
911

10-
"github.com/auth0/go-auth0/management"
12+
"github.com/chzyer/readline"
13+
"github.com/manifoldco/promptui"
14+
"github.com/mattn/go-tty"
1115
"gopkg.in/yaml.v2"
1216
)
1317

@@ -18,23 +22,28 @@ const (
1822
logCategoryWarning
1923
logCategoryFailure
2024
logCategoryUnknown
25+
colWidthType = 20
26+
colWidthDesc = 40
27+
colWidthDate = 25
28+
colWidthConnection = 20
29+
colWidthClient = 30
2130
)
2231

2332
type logCategory int
2433

25-
var _ View = &logView{}
34+
var _ View = &LogView{}
2635

27-
type logView struct {
36+
type LogView struct {
2837
silent bool
2938
*management.Log
3039
raw interface{}
3140
}
3241

33-
func (v *logView) AsTableHeader() []string {
42+
func (v *LogView) AsTableHeader() []string {
3443
return []string{"Type", "Description", "Date", "Connection", "Client"}
3544
}
3645

37-
func (v *logView) getConnection() string {
46+
func (v *LogView) getConnection() string {
3847
if v.Details["prompts"] == nil {
3948
return notApplicable
4049
}
@@ -54,7 +63,31 @@ func (v *logView) getConnection() string {
5463
return notApplicable
5564
}
5665

57-
func (v *logView) AsTableRow() []string {
66+
func (v *LogView) AsTableRowString() string {
67+
row := v.AsTableRow()
68+
return fmt.Sprintf(
69+
"%-*s %-*s %-*s %-*s %-*s",
70+
colWidthType, row[0],
71+
colWidthDesc, row[1],
72+
colWidthDate, row[2],
73+
colWidthConnection, row[3],
74+
colWidthClient, row[4],
75+
)
76+
}
77+
78+
func (v *LogView) AsTableHeaderString() string {
79+
row := v.AsTableHeader()
80+
return fmt.Sprintf(
81+
" "+"\033[4m%-*s %-*s %-*s %-*s %-*s\033[0m",
82+
colWidthType+3, row[0],
83+
colWidthDesc+14, row[1],
84+
colWidthDate, row[2],
85+
colWidthConnection, row[3],
86+
colWidthClient, row[4],
87+
)
88+
}
89+
90+
func (v *LogView) AsTableRow() []string {
5891
typ, desc := v.typeDesc()
5992

6093
clientName := v.GetClientName()
@@ -78,11 +111,11 @@ func (v *logView) AsTableRow() []string {
78111
}
79112
}
80113

81-
func (v *logView) Object() interface{} {
114+
func (v *LogView) Object() interface{} {
82115
return v.raw
83116
}
84117

85-
func (v *logView) Extras() []string {
118+
func (v *LogView) Extras() []string {
86119
if v.silent {
87120
return nil
88121
}
@@ -97,9 +130,9 @@ func (v *logView) Extras() []string {
97130
return []string{ansi.Faint(indent(string(raw), "\t"))}
98131
}
99132

100-
func (v *logView) category() logCategory {
133+
func (v *LogView) category() logCategory {
101134
switch logType := v.GetType(); {
102-
case strings.HasPrefix(logType, "s"):
135+
case strings.HasPrefix(logType, "s") || strings.HasPrefix(logType, "m"):
103136
return logCategorySuccess
104137
case strings.HasPrefix(logType, "w"):
105138
return logCategoryWarning
@@ -110,7 +143,7 @@ func (v *logView) category() logCategory {
110143
}
111144
}
112145

113-
func (v *logView) typeDesc() (typ, desc string) {
146+
func (v *LogView) typeDesc() (typ, desc string) {
114147
chunks := strings.Split(v.TypeName(), "(")
115148

116149
// NOTE(cyx): Some logs don't have a typ at all -- for those we'll
@@ -142,6 +175,55 @@ func (v *logView) typeDesc() (typ, desc string) {
142175
return typ, desc
143176
}
144177

178+
func (r *Renderer) LogPrompt(logs []*management.Log, hasFilter bool, currentIndex *int) string {
179+
resource := "logs"
180+
181+
r.Heading(resource)
182+
if len(logs) == 0 {
183+
if hasFilter {
184+
if r.Format == OutputFormatJSON {
185+
r.JSONResult([]interface{}{})
186+
return ""
187+
}
188+
r.Warnf("No logs available matching filter criteria.\n")
189+
} else {
190+
r.EmptyState(resource, "To generate logs, run a test command like 'auth0 test login' or 'auth0 test token'")
191+
}
192+
193+
return ""
194+
}
195+
196+
view := LogView{Log: logs[0]}
197+
label := view.AsTableHeaderString()
198+
var rows []string
199+
200+
// Recursively append each log from logs list.
201+
for _, l := range logs {
202+
view := LogView{Log: l}
203+
rows = append(rows, view.AsTableRowString())
204+
}
205+
206+
promptui.IconInitial = promptui.Styler()("")
207+
prompt := promptui.Select{
208+
Label: label,
209+
Items: rows,
210+
Size: 10,
211+
HideHelp: true,
212+
Stdout: &noBellStdout{},
213+
Templates: &promptui.SelectTemplates{
214+
Label: "{{ . }}",
215+
},
216+
}
217+
var err error
218+
*currentIndex, _, err = prompt.RunCursorAt(*currentIndex, *currentIndex)
219+
if err != nil {
220+
r.Errorf("failed to select a log: %w", err)
221+
}
222+
223+
// Return the ID of the select log.
224+
return logs[*currentIndex].GetLogID()
225+
}
226+
145227
func (r *Renderer) LogList(logs []*management.Log, silent, hasFilter bool) {
146228
resource := "logs"
147229

@@ -163,7 +245,7 @@ func (r *Renderer) LogList(logs []*management.Log, silent, hasFilter bool) {
163245

164246
var res []View
165247
for _, l := range logs {
166-
res = append(res, &logView{Log: l, silent: silent, raw: l})
248+
res = append(res, &LogView{Log: l, silent: silent, raw: l})
167249
}
168250

169251
r.Results(res)
@@ -174,7 +256,7 @@ func (r *Renderer) LogTail(logs []*management.Log, ch <-chan []*management.Log,
174256

175257
var res []View
176258
for _, l := range logs {
177-
res = append(res, &logView{Log: l, silent: silent, raw: l})
259+
res = append(res, &LogView{Log: l, silent: silent, raw: l})
178260
}
179261

180262
viewChan := make(chan View)
@@ -184,10 +266,41 @@ func (r *Renderer) LogTail(logs []*management.Log, ch <-chan []*management.Log,
184266

185267
for list := range ch {
186268
for _, l := range list {
187-
viewChan <- &logView{Log: l, silent: silent, raw: l}
269+
viewChan <- &LogView{Log: l, silent: silent, raw: l}
188270
}
189271
}
190272
}()
191273

192274
r.Stream(res, viewChan)
193275
}
276+
277+
// Using below code to avoid the Bell sound
278+
// when toggling up/down on prompt.
279+
type noBellStdout struct{}
280+
281+
func (n *noBellStdout) Write(p []byte) (int, error) {
282+
if len(p) == 1 && p[0] == readline.CharBell {
283+
return 0, nil
284+
}
285+
return readline.Stdout.Write(p)
286+
}
287+
288+
func (n *noBellStdout) Close() error {
289+
return readline.Stdout.Close()
290+
}
291+
292+
func (r *Renderer) QuitPrompt() bool {
293+
fmt.Print("\nPress 'q' to quit or any other key to continue...\n")
294+
295+
ContTty, _ := tty.Open()
296+
defer func(ContTty *tty.TTY) {
297+
_ = ContTty.Close()
298+
}(ContTty)
299+
300+
rn, err := ContTty.ReadRune()
301+
if err != nil {
302+
panic(err)
303+
}
304+
305+
return rn == 'q' || rn == 'Q'
306+
}

internal/display/logs_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func TestStream(t *testing.T) {
2020
}
2121

2222
results := []View{
23-
&logView{
23+
&LogView{
2424
Log: &management.Log{
2525
LogID: auth0.String("354234"),
2626
Type: auth0.String("sapi"),
@@ -51,7 +51,7 @@ API Operation Update branding settings
5151
wg.Add(1)
5252
go func() {
5353
defer wg.Done()
54-
viewChan <- &logView{
54+
viewChan <- &LogView{
5555
Log: &management.Log{
5656
LogID: auth0.String("354236"),
5757
Type: auth0.String("sapi"),

0 commit comments

Comments
 (0)