-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
41 lines (35 loc) · 990 Bytes
/
main.go
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
package main
import (
"fmt"
"github.com/alecthomas/kong"
"os"
)
type InitCmd struct{}
type HashObjectCmd struct {
W bool `short:"w" help:"Write blob"`
StdIn bool `name:"stdin" help:"Get input from stdin"`
File string `arg:"" help:"File to read from" optional:""`
}
type CatFileCmd struct {
Type string `arg:"" required:""`
Object string `arg:"" required:""`
}
type CLIArg struct {
Init *InitCmd `cmd:"" help:"Create an enpty Git repo"`
HashObject *HashObjectCmd `cmd:"" help:"Compute object ID and optionally creates a blob from a file"`
CatFile *CatFileCmd `cmd:"" help:"Provide content or type and size information for repository objects"`
}
func parse() *CLIArg {
arg := &CLIArg{}
kong.Parse(arg)
return arg
}
func main() {
args := os.Args[1:]
switch args[0] {
case "hash-object":
fmt.Println(writeGitObject(BLOB, []byte("Hello. It's a content of blob object.")))
case "cat-file":
fmt.Println(string(readGitObject(args[1])))
}
}