Skip to content

Commit ada27c4

Browse files
committed
Improvements
1 parent 1ccc6d6 commit ada27c4

8 files changed

Lines changed: 269 additions & 77 deletions

File tree

.github/ISSUE_TEMPLATE.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ _Before opening an issue, search for similar bug reports or feature requests on
44

55
**System info:**
66

7-
* **Version used (`sslcli -v`):**
8-
* **OS (e.g. from `/etc/*-release`):**
9-
* **Kernel (`uname -a`):**
7+
* **Verbose version info (`sslcli -vv`):**
108
* **Install tools:**
119

1210
**Steps to reproduce:**

.github/workflows/ci.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ on:
77
branches: [master]
88
schedule:
99
- cron: '0 13 */15 * *'
10+
workflow_dispatch:
11+
inputs:
12+
force_run:
13+
description: 'Force workflow run'
14+
required: true
15+
type: choice
16+
options: [yes, no]
17+
18+
permissions:
19+
actions: read
20+
contents: read
21+
statuses: write
1022

1123
concurrency:
1224
group: ${{ github.workflow }}-${{ github.ref }}
@@ -22,7 +34,7 @@ jobs:
2234

2335
strategy:
2436
matrix:
25-
go: [ '1.18.x', '1.19.x' ]
37+
go: [ '1.19.x', '1.20.x' ]
2638

2739
steps:
2840
- name: Set up Go
@@ -53,7 +65,7 @@ jobs:
5365
- name: Set up Go
5466
uses: actions/setup-go@v3
5567
with:
56-
go-version: '1.18.x'
68+
go-version: '1.19.x'
5769

5870
- name: Checkout
5971
uses: actions/checkout@v3

cli/cli.go

Lines changed: 56 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ import (
3030
"github.com/essentialkaos/ek/v12/usage/update"
3131

3232
"github.com/essentialkaos/sslscan/v13"
33+
34+
"github.com/essentialkaos/sslcli/cli/support"
3335
)
3436

3537
// ////////////////////////////////////////////////////////////////////////////////// //
3638

3739
const (
3840
APP = "SSLScan Client"
39-
VER = "2.7.3"
41+
VER = "2.7.4"
4042
DESC = "Command-line client for the SSL Labs API"
4143
)
4244

@@ -54,6 +56,7 @@ const (
5456
OPT_HELP = "h:help"
5557
OPT_VER = "v:version"
5658

59+
OPT_VERB_VER = "vv:verbose-version"
5760
OPT_COMPLETION = "completion"
5861
OPT_GENERATE_MAN = "generate-man"
5962
)
@@ -100,9 +103,10 @@ var optMap = options.Map{
100103
OPT_QUIET: {Type: options.BOOL},
101104
OPT_NOTIFY: {Type: options.BOOL},
102105
OPT_NO_COLOR: {Type: options.BOOL},
103-
OPT_HELP: {Type: options.BOOL, Alias: "u:usage"},
104-
OPT_VER: {Type: options.BOOL, Alias: "ver"},
106+
OPT_HELP: {Type: options.BOOL},
107+
OPT_VER: {Type: options.BOOL},
105108

109+
OPT_VERB_VER: {Type: options.BOOL},
106110
OPT_COMPLETION: {},
107111
OPT_GENERATE_MAN: {Type: options.BOOL},
108112
}
@@ -127,8 +131,12 @@ var serverMessageShown bool
127131

128132
// ////////////////////////////////////////////////////////////////////////////////// //
129133

130-
// Init starts initialization rutine
131-
func Init() {
134+
// Init is main function
135+
func Init(gitRev string, gomod []byte) {
136+
runtime.GOMAXPROCS(2)
137+
138+
preConfigureUI()
139+
132140
args, errs := options.Parse(optMap)
133141

134142
if len(errs) != 0 {
@@ -141,30 +149,50 @@ func Init() {
141149
os.Exit(1)
142150
}
143151

144-
if options.Has(OPT_COMPLETION) {
145-
os.Exit(genCompletion())
146-
}
152+
configureUI()
153+
prepare()
147154

148-
if options.Has(OPT_GENERATE_MAN) {
155+
switch {
156+
case options.Has(OPT_COMPLETION):
157+
os.Exit(genCompletion())
158+
case options.Has(OPT_GENERATE_MAN):
149159
os.Exit(genMan())
160+
case options.GetB(OPT_VER):
161+
showAbout(gitRev)
162+
os.Exit(0)
163+
case options.GetB(OPT_VERB_VER):
164+
support.ShowSupportInfo(APP, VER, gitRev, gomod)
165+
os.Exit(0)
166+
case options.GetB(OPT_HELP) || len(args) == 0:
167+
showUsage()
168+
os.Exit(0)
150169
}
151170

152-
configureUI()
153-
prepare()
171+
process(args)
172+
}
154173

155-
if options.GetB(OPT_VER) {
156-
showAbout()
157-
return
158-
}
174+
// preConfigureUI preconfigures UI based on information about user terminal
175+
func preConfigureUI() {
176+
term := os.Getenv("TERM")
159177

160-
if options.GetB(OPT_HELP) || len(args) == 0 {
161-
showUsage()
162-
return
178+
fmtc.DisableColors = true
179+
180+
if term != "" {
181+
switch {
182+
case strings.Contains(term, "xterm"),
183+
strings.Contains(term, "color"),
184+
term == "screen":
185+
fmtc.DisableColors = false
186+
}
163187
}
164188

165-
runtime.GOMAXPROCS(2)
189+
if !fsutil.IsCharacterDevice("/dev/stdout") && os.Getenv("FAKETTY") == "" {
190+
fmtc.DisableColors = true
191+
}
166192

167-
process(args)
193+
if os.Getenv("NO_COLOR") != "" {
194+
fmtc.DisableColors = true
195+
}
168196
}
169197

170198
// configureUI configures user interface
@@ -600,16 +628,16 @@ func showUsage() {
600628
}
601629

602630
// showAbout prints info about version
603-
func showAbout() {
604-
genAbout().Render()
631+
func showAbout(gitRev string) {
632+
genAbout(gitRev).Render()
605633
}
606634

607635
// genMan generates man page
608636
func genMan() int {
609637
fmt.Println(
610638
man.Generate(
611639
genUsage(),
612-
genAbout(),
640+
genAbout(""),
613641
),
614642
)
615643

@@ -661,7 +689,7 @@ func genUsage() *usage.Info {
661689
}
662690

663691
// genAbout generates info about version
664-
func genAbout() *usage.About {
692+
func genAbout(gitRev string) *usage.About {
665693
about := &usage.About{
666694
App: APP,
667695
Version: VER,
@@ -672,5 +700,9 @@ func genAbout() *usage.About {
672700
UpdateChecker: usage.UpdateChecker{"essentialkaos/sslcli", update.GitHubChecker},
673701
}
674702

703+
if gitRev != "" {
704+
about.Build = "git:" + gitRev
705+
}
706+
675707
return about
676708
}

cli/support/support.go

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
package support
2+
3+
// ////////////////////////////////////////////////////////////////////////////////// //
4+
// //
5+
// Copyright (c) 2023 ESSENTIAL KAOS //
6+
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> //
7+
// //
8+
// ////////////////////////////////////////////////////////////////////////////////// //
9+
10+
import (
11+
"fmt"
12+
"os"
13+
"runtime"
14+
"strings"
15+
16+
"github.com/essentialkaos/ek/v12/fmtc"
17+
"github.com/essentialkaos/ek/v12/fmtutil"
18+
"github.com/essentialkaos/ek/v12/fsutil"
19+
"github.com/essentialkaos/ek/v12/hash"
20+
"github.com/essentialkaos/ek/v12/strutil"
21+
"github.com/essentialkaos/ek/v12/system"
22+
23+
"github.com/essentialkaos/depsy"
24+
)
25+
26+
// ////////////////////////////////////////////////////////////////////////////////// //
27+
28+
// ShowSupportInfo prints verbose info about application, system, dependencies and
29+
// important environment
30+
func ShowSupportInfo(app, ver, gitRev string, gomod []byte) {
31+
fmtutil.SeparatorTitleColorTag = "{s-}"
32+
fmtutil.SeparatorFullscreen = false
33+
fmtutil.SeparatorColorTag = "{s-}"
34+
fmtutil.SeparatorSize = 80
35+
36+
showApplicationInfo(app, ver, gitRev)
37+
showOSInfo()
38+
showDepsInfo(gomod)
39+
40+
fmtutil.Separator(false)
41+
}
42+
43+
// ////////////////////////////////////////////////////////////////////////////////// //
44+
45+
// showApplicationInfo shows verbose information about application
46+
func showApplicationInfo(app, ver, gitRev string) {
47+
fmtutil.Separator(false, "APPLICATION INFO")
48+
49+
printInfo(7, "Name", app)
50+
printInfo(7, "Version", ver)
51+
52+
printInfo(7, "Go", fmtc.Sprintf(
53+
"%s {s}(%s/%s){!}",
54+
strings.TrimLeft(runtime.Version(), "go"),
55+
runtime.GOOS, runtime.GOARCH,
56+
))
57+
58+
if gitRev != "" {
59+
if !fmtc.DisableColors && fmtc.IsTrueColorSupported() {
60+
printInfo(7, "Git SHA", gitRev+getHashColorBullet(gitRev))
61+
} else {
62+
printInfo(7, "Git SHA", gitRev)
63+
}
64+
}
65+
66+
bin, _ := os.Executable()
67+
binSHA := hash.FileHash(bin)
68+
69+
if binSHA != "" {
70+
binSHA = strutil.Head(binSHA, 7)
71+
if !fmtc.DisableColors && fmtc.IsTrueColorSupported() {
72+
printInfo(7, "Bin SHA", binSHA+getHashColorBullet(binSHA))
73+
} else {
74+
printInfo(7, "Bin SHA", binSHA)
75+
}
76+
}
77+
}
78+
79+
// showOSInfo shows verbose information about system
80+
func showOSInfo() {
81+
osInfo, err := system.GetOSInfo()
82+
83+
if err == nil {
84+
fmtutil.Separator(false, "OS INFO")
85+
86+
printInfo(12, "Name", osInfo.Name)
87+
printInfo(12, "Pretty Name", osInfo.PrettyName)
88+
printInfo(12, "Version", osInfo.VersionID)
89+
printInfo(12, "ID", osInfo.ID)
90+
printInfo(12, "ID Like", osInfo.IDLike)
91+
printInfo(12, "Version ID", osInfo.VersionID)
92+
printInfo(12, "Version Code", osInfo.VersionCodename)
93+
printInfo(12, "CPE", osInfo.CPEName)
94+
}
95+
96+
systemInfo, err := system.GetSystemInfo()
97+
98+
if err != nil {
99+
return
100+
} else {
101+
if osInfo == nil {
102+
fmtutil.Separator(false, "SYSTEM INFO")
103+
printInfo(12, "Name", systemInfo.OS)
104+
}
105+
}
106+
107+
printInfo(12, "Arch", systemInfo.Arch)
108+
printInfo(12, "Kernel", systemInfo.Kernel)
109+
110+
containerEngine := "No"
111+
112+
switch {
113+
case fsutil.IsExist("/.dockerenv"):
114+
containerEngine = "Yes (Docker)"
115+
case fsutil.IsExist("/run/.containerenv"):
116+
containerEngine = "Yes (Podman)"
117+
}
118+
119+
fmtc.NewLine()
120+
121+
printInfo(12, "Container", containerEngine)
122+
}
123+
124+
// showDepsInfo shows information about all dependencies
125+
func showDepsInfo(gomod []byte) {
126+
deps := depsy.Extract(gomod, false)
127+
128+
if len(deps) == 0 {
129+
return
130+
}
131+
132+
fmtutil.Separator(false, "DEPENDENCIES")
133+
134+
for _, dep := range deps {
135+
if dep.Extra == "" {
136+
fmtc.Printf(" {s}%8s{!} %s\n", dep.Version, dep.Path)
137+
} else {
138+
fmtc.Printf(" {s}%8s{!} %s {s-}(%s){!}\n", dep.Version, dep.Path, dep.Extra)
139+
}
140+
}
141+
}
142+
143+
// getHashColorBullet return bullet with color from hash
144+
func getHashColorBullet(v string) string {
145+
if len(v) > 6 {
146+
v = strutil.Head(v, 6)
147+
}
148+
149+
return fmtc.Sprintf(" {#" + strutil.Head(v, 6) + "}● {!}")
150+
}
151+
152+
// printInfo formats and prints info record
153+
func printInfo(size int, name, value string) {
154+
name = name + ":"
155+
size++
156+
157+
if value == "" {
158+
fm := fmt.Sprintf(" {*}%%-%ds{!} {s-}—{!}\n", size)
159+
fmtc.Printf(fm, name)
160+
} else {
161+
fm := fmt.Sprintf(" {*}%%-%ds{!} %%s\n", size)
162+
fmtc.Printf(fm, name, value)
163+
}
164+
}
165+
166+
// ////////////////////////////////////////////////////////////////////////////////// //

0 commit comments

Comments
 (0)