diff options
Diffstat (limited to 'cmd/gitaly-git2go/main.go')
-rw-r--r-- | cmd/gitaly-git2go/main.go | 47 |
1 files changed, 36 insertions, 11 deletions
diff --git a/cmd/gitaly-git2go/main.go b/cmd/gitaly-git2go/main.go index bc25dc67c..cdd168482 100644 --- a/cmd/gitaly-git2go/main.go +++ b/cmd/gitaly-git2go/main.go @@ -3,23 +3,48 @@ package main import ( + "flag" + "fmt" "os" - - git "github.com/libgit2/git2go/v30" ) +type subcmd interface { + Flags() *flag.FlagSet + Run() error +} + +var subcommands = map[string]subcmd{ + "merge": &mergeSubcommand{}, +} + +const programName = "gitaly-git2go" + +func fatalf(format string, args ...interface{}) { + fmt.Fprintf(os.Stderr, format+"\n", args...) + os.Exit(1) +} + func main() { - repo, err := git.OpenRepository(".") - if err != nil { - os.Exit(1) + flags := flag.NewFlagSet(programName, flag.ExitOnError) + flags.Parse(os.Args) + + if flags.NArg() < 2 { + fatalf("missing subcommand") + } + + subcmd, ok := subcommands[flags.Arg(1)] + if !ok { + fatalf("unknown subcommand: %q", flags.Arg(1)) } - defer repo.Free() - head, err := repo.Head() - if err != nil { - os.Exit(1) + subcmdFlags := subcmd.Flags() + subcmdFlags.Parse(flags.Args()[2:]) + + if subcmdFlags.NArg() != 0 { + fatalf("%s: trailing arguments", subcmdFlags.Name()) } - defer head.Free() - println(head.Target().String()) + if err := subcmd.Run(); err != nil { + fatalf("%s: %s", subcmdFlags.Name(), err) + } } |