Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cli/azd/pkg/ext/hooks_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (h *HooksRunner) GetScript(hookConfig *HookConfig) (tools.Script, error) {
return nil, err
}

switch hookConfig.Shell {
switch ShellType(strings.Split(string(hookConfig.Shell), " ")[0]) {
case ShellTypeBash:
return bash.NewBashScript(h.commandRunner, h.cwd, h.env.Environ()), nil
case ShellTypePowershell:
Expand Down Expand Up @@ -158,6 +158,7 @@ func (h *HooksRunner) execHook(ctx context.Context, hookConfig *HookConfig, opti
options.StdOut = previewer
defer h.console.StopPreviewer(ctx, false)
}
options.UserPwsh = string(hookConfig.Shell)

log.Printf("Executing script '%s'\n", hookConfig.path)
res, err := script.Execute(ctx, hookConfig.path, *options)
Expand Down
2 changes: 1 addition & 1 deletion cli/azd/pkg/ext/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func createTempScript(hookConfig *HookConfig) (string, error) {
scriptHeader := []string{}
scriptFooter := []string{}

switch hookConfig.Shell {
switch ShellType(strings.Split(string(hookConfig.Shell), " ")[0]) {
case ShellTypeBash:
ext = "sh"
scriptHeader = []string{
Expand Down
2 changes: 1 addition & 1 deletion cli/azd/pkg/tools/powershell/powershell.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type powershellScript struct {
// Executes the specified powershell script
// When interactive is true will attach to stdin, stdout & stderr
func (bs *powershellScript) Execute(ctx context.Context, path string, options tools.ExecOptions) (exec.RunResult, error) {
runArgs := exec.NewRunArgs("pwsh", path).
runArgs := exec.NewRunArgs(options.UserPwsh, path).
WithCwd(bs.cwd).
WithEnv(bs.envVars).
WithShell(true)
Expand Down
6 changes: 4 additions & 2 deletions cli/azd/pkg/tools/powershell/powershell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ func Test_Powershell_Execute(t *testing.T) {
t.Run("Success", func(t *testing.T) {
mockContext := mocks.NewMockContext(context.Background())

// #nosec G101
userPwsh := "pwsh -NoProfile"
mockContext.CommandRunner.When(func(args exec.RunArgs, command string) bool {
return true
}).RespondFn(func(args exec.RunArgs) (exec.RunResult, error) {
require.Equal(t, "pwsh", args.Cmd)
require.Equal(t, userPwsh, args.Cmd)
require.Equal(t, workingDir, args.Cwd)
require.Equal(t, scriptPath, args.Args[0])
require.Equal(t, env, args.Env)
Expand All @@ -38,7 +40,7 @@ func Test_Powershell_Execute(t *testing.T) {
runResult, err := PowershellScript.Execute(
*mockContext.Context,
scriptPath,
tools.ExecOptions{Interactive: to.Ptr(true)},
tools.ExecOptions{UserPwsh: userPwsh, Interactive: to.Ptr(true)},
)

require.NotNil(t, runResult)
Expand Down
1 change: 1 addition & 0 deletions cli/azd/pkg/tools/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
type ExecOptions struct {
Interactive *bool
StdOut io.Writer
UserPwsh string
}

// Utility to easily execute a bash script across platforms
Expand Down