package main /* this parses the command line arguements this enables command line options from other packages like 'gui' and 'log' */ import ( "fmt" "os" "go.wit.com/dev/alexflint/arg" ) var argv args type args struct { Pull *EmptyCmd `arg:"subcommand:pull" help:"'git pull' on the repos"` List *EmptyCmd `arg:"subcommand:list" help:"list the repos"` Merge *EmptyCmd `arg:"subcommand:merge" help:"merge in new patchsets"` Init *EmptyCmd `arg:"subcommand:init" help:"init the repo list"` Port int `arg:"--port" default:"2520" help:"port to run on"` Hostname string `arg:"--hostname" default:"forge.wit.com" help:"hostname to use"` Daemon bool `arg:"--daemon" help:"run as a daemon"` Force bool `arg:"--force" help:"try to strong arm things"` Verbose bool `arg:"--verbose" help:"show more output"` Bash bool `arg:"--bash" help:"generate bash completion"` BashAuto []string `arg:"--auto-complete" help:"todo: move this to go-arg"` } type EmptyCmd struct { } func (args) Version() string { return ARGNAME + " " + VERSION + " Built on " + BUILDTIME } func init() { arg.MustParse(&argv) } // prints help to STDERR // TODO: move everything below this to go-args func (args) doBashHelp() { if len(argv.BashAuto) < 2 { fmt.Fprintf(os.Stderr, "something went wrong with the GO args autocomplete in %s\n", ARGNAME) return } if argv.BashAuto[1] != "''" { // if this is not blank, then the user has typed something return } if argv.BashAuto[0] != ARGNAME { fmt.Fprintln(os.Stderr, argv.BashAuto[0]) // if this is not the name of the command, the user already started doing something return } if argv.BashAuto[0] == ARGNAME { me.pp.WriteHelp(os.Stderr) return } fmt.Fprintln(os.Stderr, "") fmt.Fprintln(os.Stderr, "something went wrong with the GO args package") fmt.Fprintln(os.Stderr, "") } func (args) doBashAuto() { // argv.doBashHelp() switch argv.BashAuto[0] { case "merge": fmt.Println("--force") default: if argv.BashAuto[0] == ARGNAME { // list the subcommands here fmt.Println("list merge") } } os.Exit(0) }