diff options
-rw-r--r-- | cmd/gitaly-git2go/main.go | 47 | ||||
-rw-r--r-- | cmd/gitaly-git2go/merge.go | 19 |
2 files changed, 55 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) + } } diff --git a/cmd/gitaly-git2go/merge.go b/cmd/gitaly-git2go/merge.go new file mode 100644 index 000000000..1d2f48c4b --- /dev/null +++ b/cmd/gitaly-git2go/merge.go @@ -0,0 +1,19 @@ +// +build static,system_libgit2 + +package main + +import ( + "flag" +) + +type mergeSubcommand struct { +} + +func (cmd *mergeSubcommand) Flags() *flag.FlagSet { + flags := flag.NewFlagSet("merge", flag.ExitOnError) + return flags +} + +func (cmd *mergeSubcommand) Run() error { + return nil +} |