diff --git a/main.go b/main.go index eb9e51e6..e11f0cfc 100644 --- a/main.go +++ b/main.go @@ -3,17 +3,20 @@ package main import ( "fmt" "os" - "strings" "github.com/bfirsh/whalebrew/cmd" ) func main() { - // HACK: if first argument starts with "/", prefix the subcommand run. - // This allows us to use this command as a shebang, because we can't pass - // the argument "run" in the shebang on Linux. - if len(os.Args) > 1 && strings.HasPrefix(os.Args[1], "/") { - cmd.RootCmd.SetArgs(append([]string{"run"}, os.Args[1:]...)) + + if len(os.Args) > 1 { + // Check if not command exists + if _, _, err := cmd.RootCmd.Find(os.Args); err != nil { + // Check if file exists + if _, err := os.Stat(os.Args[1]); err == nil { + cmd.RootCmd.SetArgs(append([]string{"run"}, os.Args[1:]...)) + } + } } if err := cmd.RootCmd.Execute(); err != nil {