| 34 | } |
| 35 | |
| 36 | func main() { |
| 37 | parser, err := kong.New(&cli, |
| 38 | kong.Vars{ |
| 39 | "version": VERSION, |
| 40 | }) |
| 41 | if err != nil { |
| 42 | panic(err) |
| 43 | } |
| 44 | |
| 45 | args := os.Args[1:] |
| 46 | // Print the help if there are no args. |
| 47 | if len(args) == 0 { |
| 48 | parsed := kong.Context{ |
| 49 | Kong: parser, |
| 50 | } |
| 51 | parsed.PrintUsage(false) |
| 52 | parsed.Exit(1) |
| 53 | } |
| 54 | |
| 55 | parsed, err := parser.Parse(args) |
| 56 | parser.FatalIfErrorf(err) |
| 57 | |
| 58 | if cli.Trace { |
| 59 | finish := tracing.Start() |
| 60 | defer finish() |
| 61 | } |
| 62 | |
| 63 | if cli.NoColor { |
| 64 | color.NoColor = true |
| 65 | } |
| 66 | |
| 67 | switch parsed.Command() { |
| 68 | case "install": |
| 69 | repo, err := repo.NewRepo() |
| 70 | if err != nil { |
| 71 | panic(err) |
| 72 | } |
| 73 | |
| 74 | // TODO: Dry run option. |
| 75 | prompt := !cli.Install.Yes |
| 76 | quickhook := strings.TrimSpace(cli.Install.Bin) |
| 77 | if quickhook == "" { |
| 78 | quickhook = "quickhook" |
| 79 | } |
| 80 | err = install(repo, quickhook, prompt) |
| 81 | if err != nil { |
| 82 | panic(err) |
| 83 | } |
| 84 | |
| 85 | case "hook commit-msg <message-file>": |
| 86 | repo, err := repo.NewRepo() |
| 87 | if err != nil { |
| 88 | panic(err) |
| 89 | } |
| 90 | |
| 91 | hook := hooks.CommitMsg{ |
| 92 | Repo: repo, |
| 93 | } |