in git-codereview/review.go [78:142]
func main() {
initFlags()
if len(os.Args) < 2 {
flags.Usage()
exit(2)
}
command, args := os.Args[1], os.Args[2:]
// NOTE: Keep this switch in sync with the list of commands above.
var cmd func([]string)
switch command {
default:
flags.Usage()
exit(2) // avoid installing hooks.
case "help":
fmt.Fprintf(stdout(), help, progName)
return // avoid installing hooks.
case "hooks": // in case hooks weren't installed.
installHook(args)
return // avoid invoking installHook twice.
case "branchpoint":
cmd = cmdBranchpoint
case "change":
cmd = cmdChange
case "gofmt":
cmd = cmdGofmt
case "hook-invoke":
cmd = cmdHookInvoke
case "mail", "m":
cmd = cmdMail
case "pending":
cmd = cmdPending
case "rebase-work":
cmd = cmdRebaseWork
case "reword":
cmd = cmdReword
case "submit":
cmd = cmdSubmit
case "sync":
cmd = cmdSync
case "sync-branch":
cmd = cmdSyncBranch
case "test-loadAuth": // for testing only.
cmd = func([]string) { loadAuth() }
}
// Install hooks automatically, but only if this is a Gerrit repo.
if haveGerrit() {
// Don't pass installHook args directly,
// since args might contain args meant for other commands.
// Filter down to just global flags.
var hookArgs []string
for _, arg := range args {
switch arg {
case "-n", "-v":
hookArgs = append(hookArgs, arg)
}
}
installHook(hookArgs)
}
cmd(args)
}