1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
// +build static,system_libgit2
package main
import (
"context"
"flag"
"fmt"
"io"
"os"
"gitlab.com/gitlab-org/gitaly/cmd/gitaly-git2go/conflicts"
)
type subcmd interface {
Flags() *flag.FlagSet
Run(ctx context.Context, stdin io.Reader, stdout io.Writer) error
}
var subcommands = map[string]subcmd{
"commit": commitSubcommand{},
"conflicts": &conflicts.Subcommand{},
"merge": &mergeSubcommand{},
"revert": &revertSubcommand{},
"resolve": &resolveSubcommand{},
}
const programName = "gitaly-git2go"
func fatalf(format string, args ...interface{}) {
fmt.Fprintf(os.Stderr, format+"\n", args...)
os.Exit(1)
}
func main() {
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))
}
subcmdFlags := subcmd.Flags()
subcmdFlags.Parse(flags.Args()[2:])
if subcmdFlags.NArg() != 0 {
fatalf("%s: trailing arguments", subcmdFlags.Name())
}
if err := subcmd.Run(context.Background(), os.Stdin, os.Stdout); err != nil {
fatalf("%s: %s", subcmdFlags.Name(), err)
}
}
|