Skip to content

Commit

Permalink
Add --pause/-P option for pause between executing commands
Browse files Browse the repository at this point in the history
  • Loading branch information
andyone committed Oct 31, 2023
1 parent d6b8293 commit 3032b77
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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: {},
Expand Down Expand Up @@ -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,
}

Expand Down Expand Up @@ -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")
Expand Down
5 changes: 4 additions & 1 deletion cli/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type Executor struct {
// ExecutorConfig contains executor configuration
type Config struct {
ErrsDir string
Pause float64
DebugLines int
Quiet bool
DisableCleanup bool
Expand Down Expand Up @@ -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))
}
}
Expand Down

0 comments on commit 3032b77

Please sign in to comment.