Skip to content

Commit

Permalink
Code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
andyone committed Apr 27, 2024
1 parent 824fb62 commit 77cbaac
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
23 changes: 8 additions & 15 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/support"
"github.com/essentialkaos/ek/v12/support/deps"
"github.com/essentialkaos/ek/v12/support/pkgs"
"github.com/essentialkaos/ek/v12/terminal"
"github.com/essentialkaos/ek/v12/terminal/tty"
"github.com/essentialkaos/ek/v12/usage"
"github.com/essentialkaos/ek/v12/usage/completion/bash"
Expand All @@ -43,7 +44,7 @@ import (
// Application info
const (
APP = "bibop"
VER = "8.0.3"
VER = "8.0.4"
DESC = "Utility for testing command-line tools"
)

Expand Down Expand Up @@ -114,8 +115,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 @@ -299,10 +301,10 @@ func validate(e *executor.Executor, r *recipe.Recipe, tags []string) {
return
}

printError("Recipe validation errors:")
terminal.Error("Recipe validation errors:")

for _, err := range errs {
printError(" • %v", err)
terminal.Error(" • %v", err)
}

os.Exit(1)
Expand Down Expand Up @@ -388,18 +390,9 @@ func getRenderer() render.Renderer {
return nil
}

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

// printErrorAndExit print error message and exit with exit code 1
func printErrorAndExit(f string, a ...interface{}) {
printError(f, a...)
terminal.Error(f, a...)
os.Exit(1)
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/buger/jsonparser v1.1.1
github.com/creack/pty v1.1.21
github.com/essentialkaos/check v1.4.0
github.com/essentialkaos/ek/v12 v12.116.0
github.com/essentialkaos/ek/v12 v12.118.0
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ github.com/essentialkaos/check v1.4.0 h1:kWdFxu9odCxUqo1NNFNJmguGrDHgwi3A8daXX1n
github.com/essentialkaos/check v1.4.0/go.mod h1:LMKPZ2H+9PXe7Y2gEoKyVAwUqXVgx7KtgibfsHJPus0=
github.com/essentialkaos/depsy v1.1.0 h1:U6dp687UkQwXlZU17Hg2KMxbp3nfZAoZ8duaeUFYvJI=
github.com/essentialkaos/depsy v1.1.0/go.mod h1:kpiTAV17dyByVnrbNaMcZt2jRwvuXClUYOzpyJQwtG8=
github.com/essentialkaos/ek/v12 v12.116.0 h1:lEe1pakqCFgbJMBQ+Ymrbd0GvzXdtg9/0nB6lgpuH6o=
github.com/essentialkaos/ek/v12 v12.116.0/go.mod h1:L3l8wkmXO9T72+hXc4nZosl7tj49XiU0gVrwiXyiYBg=
github.com/essentialkaos/ek/v12 v12.118.0 h1:fosk+jCK9GrrnPiua1O6PQSwrlQ25arwespB6fnbi9g=
github.com/essentialkaos/ek/v12 v12.118.0/go.mod h1:VVCk0ZA3CB5lPkQ7bUHo/mOBs02jkjMRlLS8ES2TQpw=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
Expand Down

0 comments on commit 77cbaac

Please sign in to comment.