-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
68 lines (60 loc) · 1.51 KB
/
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"gitsnap/git"
"gitsnap/options"
"gitsnap/util"
"log"
"os"
"github.com/urfave/cli/v2"
)
const VERSION = "1.23"
func main() {
cli.AppHelpTemplate =
`NAME:
{{.Name}} - {{.Version}} - {{.Usage}}
USAGE:
{{.Name}}{{range .Flags}}{{if and (not (eq .Name "help")) (not (eq .Name "version")) }} {{if .Required}}--{{.Name}} value{{end}}{{end}}{{end}} [optional flags]
OPTIONS:
{{range .Flags}}{{.}}
{{end}}
EXIT CODES:
0 Success
101 Some file name is too long
201 Clone path is invalid (fs-wise)
202 Clone path is invalid (git-wise)
203 Output path is invalid
204 Short sha is not supported
205 Provided revision could not be found
206 Double check for files discrepancy failed
207 HEAD ref not found
208 tree not found
1 Any other error
`
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
log.SetOutput(os.Stdout)
app := &cli.App{
Name: "git-snap",
Usage: "Create a git revision snapshot for an existing repository clone. Symbolic link files will be omitted.",
Flags: options.Flags,
Version: VERSION,
Action: func(ctx *cli.Context) error {
opts, err := options.ParseOptions(ctx)
if err != nil {
return err
}
err = git.Snapshot(opts)
if err == nil {
log.Printf("Completed successfully at %v", opts.OutputPath)
}
return err
},
}
err := app.Run(os.Args)
if err != nil {
log.Printf("failed: %v", err)
if errorWithCode, isWithCode := err.(*util.ErrorWithCode); isWithCode {
os.Exit(errorWithCode.StatusCode)
}
os.Exit(1)
}
}