| 1 |
package main |
| 2 |
|
| 3 |
import ( |
| 4 |
"os" |
| 5 |
"path/filepath" |
| 6 |
|
| 7 |
"github.com/jessevdk/go-flags" |
| 8 |
) |
| 9 |
|
| 10 |
const ( |
| 11 |
bin = "go-git" |
| 12 |
receivePackBin = "git-receive-pack" |
| 13 |
uploadPackBin = "git-upload-pack" |
| 14 |
) |
| 15 |
|
| 16 |
func main() { |
| 17 |
switch filepath.Base(os.Args[0]) { |
| 18 |
case receivePackBin: |
| 19 |
os.Args = append([]string{"git", "receive-pack"}, os.Args[1:]...) |
| 20 |
case uploadPackBin: |
| 21 |
os.Args = append([]string{"git", "upload-pack"}, os.Args[1:]...) |
| 22 |
} |
| 23 |
|
| 24 |
parser := flags.NewNamedParser(bin, flags.Default) |
| 25 |
parser.AddCommand("update-server-info", "", "", &CmdUpdateServerInfo{}) |
| 26 |
parser.AddCommand("receive-pack", "", "", &CmdReceivePack{}) |
| 27 |
parser.AddCommand("upload-pack", "", "", &CmdUploadPack{}) |
| 28 |
parser.AddCommand("version", "Show the version information.", "", &CmdVersion{}) |
| 29 |
|
| 30 |
_, err := parser.Parse() |
| 31 |
if err != nil { |
| 32 |
if e, ok := err.(*flags.Error); ok && e.Type == flags.ErrCommandRequired { |
| 33 |
parser.WriteHelp(os.Stdout) |
| 34 |
} |
| 35 |
|
| 36 |
os.Exit(1) |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
type cmd struct { |
| 41 |
Verbose bool `short:"v" description:"Activates the verbose mode"` |
| 42 |
} |