Skip to content

Commit

Permalink
Code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
andyone committed Jun 23, 2024
1 parent ffefa17 commit 95ed86e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 25 deletions.
28 changes: 10 additions & 18 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/essentialkaos/ek/v12/strutil"
"github.com/essentialkaos/ek/v12/support"
"github.com/essentialkaos/ek/v12/support/deps"
"github.com/essentialkaos/ek/v12/terminal"
"github.com/essentialkaos/ek/v12/timeutil"
"github.com/essentialkaos/ek/v12/usage"
"github.com/essentialkaos/ek/v12/usage/completion/bash"
Expand All @@ -39,7 +40,7 @@ import (

const (
APP = "SSLScan Client"
VER = "3.0.0"
VER = "3.0.1"
DESC = "Command-line client for the SSL Labs API"
)

Expand Down Expand Up @@ -156,8 +157,9 @@ func Run(gitRev string, gomod []byte) {

args, errs := options.Parse(optMap)

if len(errs) != 0 {
printError(errs[0].Error())
if !errs.IsEmpty() {
terminal.Error("Options parsing errors:")
terminal.Error(errs.String())
os.Exit(1)
}

Expand Down Expand Up @@ -189,7 +191,7 @@ func Run(gitRev string, gomod []byte) {
err = prepare()

if err != nil {
printError(err.Error())
terminal.Error(err)
os.Exit(1)
}

Expand All @@ -201,7 +203,7 @@ func Run(gitRev string, gomod []byte) {
}

if err != nil {
printError(err.Error())
terminal.Error(err)
}

if !ok {
Expand Down Expand Up @@ -253,8 +255,8 @@ func checkForEmail() {
return
}

printError("You must provide an email address to make requests to the API.")
printError(
terminal.Error("You must provide an email address to make requests to the API.")
terminal.Error(
"You can provide it using %s option, or using SSLLABS_EMAIL environment variable.",
options.Format(OPT_EMAIL),
)
Expand Down Expand Up @@ -684,11 +686,6 @@ func getNormGrade(grade string) string {
}
}

// printError prints error message to console
func printError(f string, a ...interface{}) {
fmtc.Fprintf(os.Stderr, "{r}"+f+"{!}\n", a...)
}

// ////////////////////////////////////////////////////////////////////////////////// //

// checkAPIAvailability checks SSLLabs API availability
Expand Down Expand Up @@ -735,12 +732,7 @@ func printCompletion() int {

// printMan prints man page
func printMan() {
fmt.Println(
man.Generate(
genUsage(),
genAbout(""),
),
)
fmt.Println(man.Generate(genUsage(), genAbout("")))
}

// genUsage generates usage info
Expand Down
5 changes: 3 additions & 2 deletions cli/details.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/essentialkaos/ek/v12/pluralize"
"github.com/essentialkaos/ek/v12/sliceutil"
"github.com/essentialkaos/ek/v12/strutil"
"github.com/essentialkaos/ek/v12/terminal"
"github.com/essentialkaos/ek/v12/timeutil"

sslscan "github.com/essentialkaos/sslscan/v14"
Expand Down Expand Up @@ -63,12 +64,12 @@ func printDetailedInfo(ap *sslscan.AnalyzeProgress, fromCache bool) {
info, err := ap.Info(true, fromCache)

if err != nil {
printError("\nCan't fetch full analyze info: %v\n", err)
terminal.Error("\nCan't fetch full analyze info: %v\n", err)
return
}

if strings.ToUpper(info.Status) != "READY" {
printError("\n%s\n", info.StatusMessage)
terminal.Error("\n%s\n", info.StatusMessage)
return
}

Expand Down
12 changes: 7 additions & 5 deletions common/sslcli.spec
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

Summary: Pretty awesome command-line client for public SSLLabs API
Name: sslcli
Version: 3.0.0
Version: 3.0.1
Release: 0%{?dist}
Group: Applications/System
License: Apache License, Version 2.0
Expand All @@ -22,7 +22,7 @@ Source100: checksum.sha512

BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)

BuildRequires: golang >= 1.20
BuildRequires: golang >= 1.21

Provides: %{name} = %{version}-%{release}

Expand All @@ -37,13 +37,15 @@ Pretty awesome command-line client for public SSLLabs API.
%{crc_check}

%setup -q

%build
if [[ ! -d "%{name}/vendor" ]] ; then
echo "This package requires vendored dependencies"
echo -e "----\nThis package requires vendored dependencies\n----"
exit 1
elif [[ -f "%{name}/%{name}" ]] ; then
echo -e "----\nSources must not contain precompiled binaries\n----"
exit 1
fi

%build
pushd %{name}
go build %{name}.go
cp LICENSE ..
Expand Down

0 comments on commit 95ed86e

Please sign in to comment.