MCPcopy Index your code
hub / github.com/cortesi/modd / CheckShell

Function CheckShell

shell/shell.go:176–199  ·  view source on GitHub ↗

CheckShell checks that a shell is supported, and returns the correct command name

(shell string)

Source from the content-addressed store, hash-verified

174
175// CheckShell checks that a shell is supported, and returns the correct command name
176func 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
201func makeCommand(shell string, command string, dir string) (*exec.Cmd, error) {
202 shcmd, err := CheckShell(shell)

Callers 2

makeCommandFunction · 0.85
TestShellsFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestShellsFunction · 0.68