CheckShell checks that a shell is supported, and returns the correct command name
(shell string)
| 174 | |
| 175 | // CheckShell checks that a shell is supported, and returns the correct command name |
| 176 | func CheckShell(shell string) (string, error) { |
| 177 | if _, ok := ValidShells[shell]; !ok { |
| 178 | return "", fmt.Errorf("unsupported shell: %q", shell) |
| 179 | } |
| 180 | switch shell { |
| 181 | case "powershell": |
| 182 | if _, err := exec.LookPath("powershell"); err == nil { |
| 183 | return "powershell", nil |
| 184 | } else if _, err := exec.LookPath("pwsh"); err == nil { |
| 185 | return "pwsh", nil |
| 186 | } else { |
| 187 | return "", fmt.Errorf("powershell/pwsh not on path") |
| 188 | } |
| 189 | case "modd": |
| 190 | // When testing, we're running under a special compiled test executable, |
| 191 | // so we look for an instance of modd on our path. |
| 192 | if shellTesting { |
| 193 | return exec.LookPath("modd") |
| 194 | } |
| 195 | return os.Executable() |
| 196 | default: |
| 197 | return exec.LookPath(shell) |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | func makeCommand(shell string, command string, dir string) (*exec.Cmd, error) { |
| 202 | shcmd, err := CheckShell(shell) |
no outgoing calls