From 3032b778b468d7b15583498fc936d9b2d3ebbe82 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Wed, 1 Nov 2023 01:06:45 +0300 Subject: [PATCH] Add --pause/-P option for pause between executing commands --- cli/cli.go | 4 ++++ cli/executor/executor.go | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cli/cli.go b/cli/cli.go index eef4e5b7..a4f39c70 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -55,6 +55,7 @@ const ( OPT_BARCODE = "B:barcode" OPT_EXTRA = "X:extra" OPT_TIME = "T:time" + OPT_PAUSE = "P:pause" OPT_FORMAT = "f:format" OPT_DIR = "d:dir" OPT_PATH = "p:path" @@ -82,6 +83,7 @@ var optMap = options.Map{ OPT_BARCODE: {Type: options.BOOL}, OPT_EXTRA: {Type: options.INT, Value: 10, Min: 1, Max: 256}, OPT_TIME: {Type: options.BOOL}, + OPT_PAUSE: {Type: options.FLOAT, Max: 60}, OPT_FORMAT: {}, OPT_DIR: {}, OPT_PATH: {}, @@ -278,6 +280,7 @@ func process(file string) { Quiet: options.GetB(OPT_QUIET), DisableCleanup: options.GetB(OPT_NO_CLEANUP), DebugLines: options.GetI(OPT_EXTRA), + Pause: options.GetF(OPT_PAUSE), ErrsDir: errDir, } @@ -451,6 +454,7 @@ func genUsage() *usage.Info { info.AddOption(OPT_DRY_RUN, "Parse and validate recipe") info.AddOption(OPT_EXTRA, "Number of output lines for failed action {s-}(default: 10){!}", "lines") + info.AddOption(OPT_PAUSE, "Pause between commands in seconds", "duration") 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") diff --git a/cli/executor/executor.go b/cli/executor/executor.go index 02b0c1b1..dd184009 100644 --- a/cli/executor/executor.go +++ b/cli/executor/executor.go @@ -55,6 +55,7 @@ type Executor struct { // ExecutorConfig contains executor configuration type Config struct { ErrsDir string + Pause float64 DebugLines int Quiet bool DisableCleanup bool @@ -278,7 +279,9 @@ func processRecipe(e *Executor, rr render.Renderer, r *recipe.Recipe, tags []str rr.CommandDone(command, isLastCommand) } - if r.Delay > 0 { + if e.config.Pause > 0 { + time.Sleep(timeutil.SecondsToDuration(e.config.Pause)) + } else if r.Delay > 0 { time.Sleep(timeutil.SecondsToDuration(r.Delay)) } }