Skip to content

Commit d4ddc71

Browse files
committed
Add '-G'/'--pager' option to use pager for long output
1 parent e86aaba commit d4ddc71

1 file changed

Lines changed: 37 additions & 31 deletions

File tree

cli/cli.go

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/essentialkaos/ek/v12/fmtutil"
2222
"github.com/essentialkaos/ek/v12/fsutil"
2323
"github.com/essentialkaos/ek/v12/options"
24+
"github.com/essentialkaos/ek/v12/pager"
2425
"github.com/essentialkaos/ek/v12/strutil"
2526
"github.com/essentialkaos/ek/v12/usage"
2627
"github.com/essentialkaos/ek/v12/usage/completion/bash"
@@ -38,7 +39,7 @@ import (
3839

3940
const (
4041
APP = "SSLScan Client"
41-
VER = "2.7.5"
42+
VER = "2.8.0"
4243
DESC = "Command-line client for the SSL Labs API"
4344
)
4445

@@ -52,6 +53,7 @@ const (
5253
OPT_MAX_LEFT = "M:max-left"
5354
OPT_QUIET = "q:quiet"
5455
OPT_NOTIFY = "n:notify"
56+
OPT_PAGER = "G:pager"
5557
OPT_NO_COLOR = "nc:no-color"
5658
OPT_HELP = "h:help"
5759
OPT_VER = "v:version"
@@ -102,6 +104,7 @@ var optMap = options.Map{
102104
OPT_PERFECT: {Type: options.BOOL},
103105
OPT_QUIET: {Type: options.BOOL},
104106
OPT_NOTIFY: {Type: options.BOOL},
107+
OPT_PAGER: {Type: options.BOOL},
105108
OPT_NO_COLOR: {Type: options.BOOL},
106109
OPT_HELP: {Type: options.BOOL},
107110
OPT_VER: {Type: options.MIXED},
@@ -129,14 +132,14 @@ var api *sslscan.API
129132
var maxLeftToExpiry int64
130133
var serverMessageShown bool
131134

135+
var colorTagApp, colorTagVer string
136+
132137
// ////////////////////////////////////////////////////////////////////////////////// //
133138

134139
// Run is main function
135140
func Run(gitRev string, gomod []byte) {
136141
runtime.GOMAXPROCS(2)
137142

138-
preConfigureUI()
139-
140143
args, errs := options.Parse(optMap)
141144

142145
if len(errs) != 0 {
@@ -167,33 +170,22 @@ func Run(gitRev string, gomod []byte) {
167170
process(args)
168171
}
169172

170-
// preConfigureUI preconfigures UI based on information about user terminal
171-
func preConfigureUI() {
172-
term := os.Getenv("TERM")
173-
174-
fmtc.DisableColors = true
175-
176-
if term != "" {
177-
switch {
178-
case strings.Contains(term, "xterm"),
179-
strings.Contains(term, "color"),
180-
term == "screen":
181-
fmtc.DisableColors = false
182-
}
183-
}
184-
185-
if os.Getenv("NO_COLOR") != "" {
186-
fmtc.DisableColors = true
187-
}
188-
}
189-
190173
// configureUI configures user interface
191174
func configureUI() {
192175
if options.GetB(OPT_NO_COLOR) {
193176
fmtc.DisableColors = true
194177
}
195178

196179
fmtutil.SeparatorSymbol = "–"
180+
181+
switch {
182+
case fmtc.IsTrueColorSupported():
183+
colorTagApp, colorTagVer = "{*}{#875FFF}", "{#875FFF}"
184+
case fmtc.Is256ColorsSupported():
185+
colorTagApp, colorTagVer = "{*}{#99}", "{#99}"
186+
default:
187+
colorTagApp, colorTagVer = "{*}{b}", "{c}"
188+
}
197189
}
198190

199191
// prepare prepares utility for processing data
@@ -341,6 +333,12 @@ func check(host string) (string, bool) {
341333
}
342334

343335
if options.GetB(OPT_DETAILED) {
336+
if options.GetB(OPT_PAGER) {
337+
if pager.Setup() == nil {
338+
defer pager.Complete()
339+
}
340+
}
341+
344342
printDetailedInfo(ap, true)
345343
}
346344

@@ -620,11 +618,11 @@ func printCompletion() int {
620618

621619
switch options.GetS(OPT_COMPLETION) {
622620
case "bash":
623-
fmt.Printf(bash.Generate(info, "sslcli"))
621+
fmt.Print(bash.Generate(info, "sslcli"))
624622
case "fish":
625-
fmt.Printf(fish.Generate(info, "sslcli"))
623+
fmt.Print(fish.Generate(info, "sslcli"))
626624
case "zsh":
627-
fmt.Printf(zsh.Generate(info, optMap, "sslcli"))
625+
fmt.Print(zsh.Generate(info, optMap, "sslcli"))
628626
default:
629627
return 1
630628
}
@@ -646,6 +644,8 @@ func printMan() {
646644
func genUsage() *usage.Info {
647645
info := usage.NewInfo("", "host…")
648646

647+
info.AppNameColorTag = colorTagApp
648+
649649
info.AddOption(OPT_FORMAT, "Output result in different formats", "text|json|yaml|xml")
650650
info.AddOption(OPT_DETAILED, "Show detailed info for each endpoint")
651651
info.AddOption(OPT_IGNORE_MISMATCH, "Proceed with assessments on certificate mismatch")
@@ -655,6 +655,7 @@ func genUsage() *usage.Info {
655655
info.AddOption(OPT_MAX_LEFT, "Check expiry date {s-}(num + d/w/m/y){!}", "duration")
656656
info.AddOption(OPT_NOTIFY, "Notify when check is done")
657657
info.AddOption(OPT_QUIET, "Don't show any output")
658+
info.AddOption(OPT_PAGER, "Use pager for long output")
658659
info.AddOption(OPT_NO_COLOR, "Disable colors in output")
659660
info.AddOption(OPT_HELP, "Show this help message")
660661
info.AddOption(OPT_VER, "Show version")
@@ -671,11 +672,16 @@ func genUsage() *usage.Info {
671672
// genAbout generates info about version
672673
func genAbout(gitRev string) *usage.About {
673674
about := &usage.About{
674-
App: APP,
675-
Version: VER,
676-
Desc: DESC,
677-
Year: 2009,
678-
Owner: "ESSENTIAL KAOS",
675+
App: APP,
676+
Version: VER,
677+
Desc: DESC,
678+
Year: 2009,
679+
Owner: "ESSENTIAL KAOS",
680+
681+
AppNameColorTag: colorTagApp,
682+
VersionColorTag: colorTagVer,
683+
DescSeparator: "{s}—{!}",
684+
679685
License: "Apache License, Version 2.0 <http://www.apache.org/licenses/LICENSE-2.0>",
680686
UpdateChecker: usage.UpdateChecker{"essentialkaos/sslcli", update.GitHubChecker},
681687
}

0 commit comments

Comments
 (0)