Skip to content

Commit

Permalink
Code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
andyone committed Jun 24, 2024
1 parent 1f1af55 commit 4ad810f
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/essentialkaos/ek/v12/options"
"github.com/essentialkaos/ek/v12/support"
"github.com/essentialkaos/ek/v12/support/deps"
"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 Down Expand Up @@ -94,8 +95,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 @@ -170,14 +172,14 @@ func process(query string) {
data, err := readData()

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

yaml, err := simpleyaml.NewYaml(data)

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

Expand Down Expand Up @@ -307,7 +309,7 @@ func processData(processor []string, data []*simpleyaml.Yaml) {
case "sort":
result = processorFuncSort(result)
default:
printError("Unknown function \"%s\"", pf)
terminal.Error("Unknown function \"%s\"", pf)
os.Exit(1)
}
}
Expand Down Expand Up @@ -543,11 +545,6 @@ func encodeYaml(yaml *simpleyaml.Yaml) {
fmt.Println(string(data[:len(data)-1]))
}

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

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

// IsArrayToken returns true if it array selector token
Expand Down Expand Up @@ -581,12 +578,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

0 comments on commit 4ad810f

Please sign in to comment.