Remove a bunch of package level variables
Variables for flags and things are better defined inside main().
@@ -14,20 +14,8 @@ import (
"github.com/constabulary/gb/internal/debug"
)
-var (
- fs = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
- cwd string
-)
-
-const (
// disable to keep working directory
- destroyContext = true
-)
-
-func init() {
- fs.StringVar(&cwd, "R", cmd.MustGetwd(), "set the project root") // actually the working directory to start the project root search
- fs.Usage = usage
-}
+const destroyContext = true
var commands = make(map[string]*cmd.Command)
@@ -57,10 +45,16 @@ func fatalf(format string, args ...interface{}) {
}
func main() {
+ fs := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
+ var cwd string
+ fs.StringVar(&cwd, "R", cmd.MustGetwd(), "set the project root") // actually the working directory to start the project root search
+ fs.Usage = usage
+
args := os.Args
if len(args) < 2 || args[1] == "-h" {
- fs.Usage() // usage calles exit(2)
+ fs.Usage() // usage calls exit(2)
}
+
name := args[1]
if name == "help" {
help(args[2:])
@@ -73,8 +67,7 @@ func main() {
command.AddFlags(fs)
// parse 'em
- err := command.FlagParse(fs, args)
- if err != nil {
+ if err := command.FlagParse(fs, args); err != nil {
fatalf("could not parse flags: %v", err)
}
@@ -135,7 +128,7 @@ func lookupCommand(name string) *cmd.Command {
plugin, err := lookupPlugin(name)
if err != nil {
fmt.Fprintf(os.Stderr, "FATAL: unknown command %q\n", name)
- fs.Usage() // usage calles exit(2)
+ usage()
}
command = &cmd.Command{
Run: func(ctx *gb.Context, args []string) error {
