Skip to content

Commit

Permalink
Code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
andyone committed Oct 31, 2023
1 parent 844fdd8 commit d6b8293
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
4 changes: 2 additions & 2 deletions action/auxi.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ func (c *OutputContainer) Tail(lines int) string {
}

if line == lines {
return strings.TrimRight(string(data[i+1:]), " \n\r")
return strings.Trim(string(data[i+1:]), " \n\r")
}
}

return strings.TrimRight(string(data), " \n\r")
return strings.Trim(string(data), " \n\r")
}

// IsEmpty returns true if container is empty
Expand Down
10 changes: 3 additions & 7 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/essentialkaos/ek/v12/fmtutil/panel"
"github.com/essentialkaos/ek/v12/fmtutil/table"
"github.com/essentialkaos/ek/v12/fsutil"
"github.com/essentialkaos/ek/v12/mathutil"
"github.com/essentialkaos/ek/v12/options"
"github.com/essentialkaos/ek/v12/req"
"github.com/essentialkaos/ek/v12/strutil"
Expand Down Expand Up @@ -81,7 +80,7 @@ var optMap = options.Map{
OPT_LIST_PACKAGES_FLAT: {Type: options.BOOL},
OPT_VARIABLES: {Type: options.BOOL},
OPT_BARCODE: {Type: options.BOOL},
OPT_EXTRA: {Type: options.MIXED},
OPT_EXTRA: {Type: options.INT, Value: 10, Min: 1, Max: 256},
OPT_TIME: {Type: options.BOOL},
OPT_FORMAT: {},
OPT_DIR: {},
Expand Down Expand Up @@ -278,13 +277,10 @@ func process(file string) {
cfg := &executor.Config{
Quiet: options.GetB(OPT_QUIET),
DisableCleanup: options.GetB(OPT_NO_CLEANUP),
DebugLines: options.GetI(OPT_EXTRA),
ErrsDir: errDir,
}

if options.GetB(OPT_EXTRA) {
cfg.DebugLines = mathutil.Max(10, options.GetI(OPT_EXTRA))
}

e := executor.NewExecutor(cfg)
tags := strutil.Fields(options.GetS(OPT_TAG))

Expand Down Expand Up @@ -454,7 +450,7 @@ func genUsage() *usage.Info {
info.AppNameColorTag = "{*}" + colorTagApp

info.AddOption(OPT_DRY_RUN, "Parse and validate recipe")
info.AddOption(OPT_EXTRA, "Print the last lines from command output if action was failed", "?lines")
info.AddOption(OPT_EXTRA, "Number of output lines for failed action {s-}(default: 10){!}", "lines")
info.AddOption(OPT_LIST_PACKAGES, "List required packages")
info.AddOption(OPT_LIST_PACKAGES_FLAT, "List required packages in one line {s-}(useful for scripts){!}")
info.AddOption(OPT_VARIABLES, "List recipe variables")
Expand Down
2 changes: 1 addition & 1 deletion cli/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func runCommand(e *Executor, rr render.Renderer, c *recipe.Command) bool {
}

if err != nil {
if !e.config.Quiet && e.config.DebugLines > 0 && cmdEnv != nil && !cmdEnv.output.IsEmpty() {
if !e.config.Quiet && cmdEnv != nil && !cmdEnv.output.IsEmpty() {
fmtc.NewLine()
panel.Panel(
"☴ OUTPUT", "{y}",
Expand Down

0 comments on commit d6b8293

Please sign in to comment.