diff --git a/demo.go b/demo.go index 25b8eb6..532f257 100644 --- a/demo.go +++ b/demo.go @@ -45,6 +45,9 @@ const ( // FlagSkipSteps is the flag for skipping n amount of steps. FlagSkipSteps = "skip-steps" + + // FlagShell is the flag for defining the shell that is used to execute the command(s). + FlagShell = "shell" ) // New creates a new Demo instance. @@ -90,6 +93,11 @@ func New() *Demo { Aliases: []string{"s"}, Usage: "skip the amount of initial steps within the demo", }, + &cli.StringFlag{ + Name: FlagShell, + Usage: "define the shell that is used to execute the command(s)", + DefaultText: "bash", + }, } emptyFn := func(*cli.Context) error { return nil } diff --git a/run.go b/run.go index a020a79..7be535e 100644 --- a/run.go +++ b/run.go @@ -15,10 +15,6 @@ import ( "github.com/urfave/cli/v2" ) -// Every command will be executed in a new bash subshell. This is the only -// external dependency we need. -const bash = "bash" - // errOutputNil is the error returned if no output has been set. var errOutputNil = errors.New("provided output is nil") @@ -47,6 +43,7 @@ type Options struct { HideDescriptions bool Immediate bool SkipSteps int + Shell string } func emptyFn() error { return nil } @@ -72,6 +69,7 @@ func optionsFrom(ctx *cli.Context) Options { HideDescriptions: ctx.Bool(FlagHideDescriptions), Immediate: ctx.Bool(FlagImmediate), SkipSteps: ctx.Int(FlagSkipSteps), + Shell: ctx.String(FlagShell), } } @@ -117,6 +115,10 @@ func (r *Run) Run(ctx *cli.Context) error { // RunWithOptions executes the run with the provided Options. func (r *Run) RunWithOptions(opts Options) error { + if opts.Shell == "" { + opts.Shell = "bash" + } + if err := r.setup(); err != nil { return err } @@ -207,7 +209,7 @@ func (s *step) echo(current, max int) { func (s *step) execute() error { joinedCommand := strings.Join(s.command, " ") - cmd := exec.Command(bash, "-c", joinedCommand) + cmd := exec.Command(s.r.options.Shell, "-c", joinedCommand) //nolint:gosec we're purposefully running user-provided code cmd.Stderr = s.r.out cmd.Stdout = s.r.out