5
5
"os/exec"
6
6
"path/filepath"
7
7
"runtime"
8
+ "strings"
8
9
9
10
"github.com/urfave/cli"
10
11
"go.step.sm/cli-utils/step"
@@ -19,7 +20,22 @@ func LookPath(name string) (string, error) {
19
20
fileName := "step-" + name + "-plugin"
20
21
switch runtime .GOOS {
21
22
case "windows" :
22
- for _ , ext := range []string {".com" , ".exe" , ".bat" , ".cmd" } {
23
+ var exts []string
24
+ x := os .Getenv (`PATHEXT` )
25
+ if x != "" {
26
+ for _ , e := range strings .Split (strings .ToLower (x ), `;` ) {
27
+ if e == "" {
28
+ continue
29
+ }
30
+ if e [0 ] != '.' {
31
+ e = "." + e
32
+ }
33
+ exts = append (exts , e )
34
+ }
35
+ } else {
36
+ exts = []string {".com" , ".exe" , ".bat" , ".cmd" , ".ps1" }
37
+ }
38
+ for _ , ext := range exts {
23
39
path := filepath .Join (step .BasePath (), "plugins" , fileName + ext )
24
40
if _ , err := os .Stat (path ); err == nil {
25
41
return path , nil
@@ -38,8 +54,16 @@ func LookPath(name string) (string, error) {
38
54
// it to complete.
39
55
func Run (ctx * cli.Context , file string ) error {
40
56
args := ctx .Args ()
41
- //nolint:gosec // arguments controlled by step.
42
- cmd := exec .Command (file , args [1 :]... )
57
+ cmdName := file
58
+
59
+ // if running on Windows and (likely) a PowerShell script, invoke powershell
60
+ // with the arguments instead of the plugin file directly.
61
+ if runtime .GOOS == "windows" && strings .ToLower (filepath .Ext (file )) == ".ps1" {
62
+ cmdName = "powershell"
63
+ args = append ([]string {args [0 ], "-noprofile" , "-nologo" , file }, args [1 :]... )
64
+ }
65
+
66
+ cmd := exec .Command (cmdName , args [1 :]... )
43
67
cmd .Stdin = os .Stdin
44
68
cmd .Stdout = os .Stdout
45
69
cmd .Stderr = os .Stderr
0 commit comments