Skip to content

Commit

Permalink
Fix checking args (for working on windows)
Browse files Browse the repository at this point in the history
  • Loading branch information
3846masa committed Jan 31, 2017
1 parent 276a9cd commit 926f422
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 926f422

Please sign in to comment.