package main

import (
	"fmt"
	"github.com/leocassarani/pew/command"
	"os"
)

func main() {
	args := os.Args
	if len(args) < 2 {
		printUsage(args)
		os.Exit(1)
	}

	cmd := args[1]
	cmdArgs := args[2:]

	switch cmd {
	case "run":
		err := command.Run(cmdArgs)
		exit(err)
	case "help":
		fallthrough
	case "--help":
		printUsage(args)
		exit(nil)
	default:
		err := fmt.Errorf("'%s' is not a command. See '%s --help'.", cmd, args[0])
		exit(err)
	}

}

func exit(err error) {
	if err != nil {
		log(err)
		os.Exit(1)
	}
	os.Exit(0)
}

func log(err error) {
	fmt.Fprintf(os.Stderr, "pew: %v\n", err)
}

func printUsage(args []string) {
	fmt.Printf("usage: %s <command>\n", args[0])
}

package main

import (
	"fmt"
	"github.com/leocassarani/pew/command"
	"os"
)

func main() {
	args := os.Args
	if len(args) < 2 {
		printUsage(args)
		os.Exit(1)
	}

	cmd := args[1]
	cmdArgs := args[2:]

	switch cmd {
	case "run":
		err := command.Run(cmdArgs)
		exit(err)
	case "help":
		fallthrough
	case "--help":
		printUsage(args)
		os.Exit(0)
	}

}

func exit(err error) {
	if err != nil {
		log(err)
		os.Exit(1)
	}
	os.Exit(0)
}

func log(err error) {
	fmt.Fprintf(os.Stderr, "pew: %v\n", err)
}

func printUsage(args []string) {
	fmt.Printf("usage: %s <command>\n", args[0])
}

--- 
+++ 
@@ -24,7 +24,10 @@
 		fallthrough
 	case "--help":
 		printUsage(args)
-		os.Exit(0)
+		exit(nil)
+	default:
+		err := fmt.Errorf("'%s' is not a command. See '%s --help'.", cmd, args[0])
+		exit(err)
 	}
 
 }
Handle unrecognised CLI commands in a git-like fashion
