-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathmain.go
More file actions
92 lines (82 loc) · 2.04 KB
/
main.go
File metadata and controls
92 lines (82 loc) · 2.04 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"fmt"
"log"
"os"
"github.com/urfave/cli/v2"
)
// MaxConcurrentClones is the upper limit of the maximum number of
// concurrent git clones
const MaxConcurrentClones = 20
const defaultMaxUserMigrationRetry = 5
var gitHostToken string
var useHTTPSClone *bool
var ignorePrivate *bool
var gitHostUsername string
// The services we know of and their default public host names
var knownServices = map[string]string{
"github": "github.com",
"gitlab": "gitlab.com",
"bitbucket": "bitbucket.org",
"forgejo": "codeberg.org",
}
func main() {
app := &cli.App{
Name: "gitbackup",
Usage: "Backup your Git repositories from GitHub, GitLab, Bitbucket, or Forgejo",
Flags: appFlags(),
Action: func(cCtx *cli.Context) error {
c, err := buildConfig(cCtx)
if err != nil {
return err
}
err = validateConfig(c)
if err != nil {
return err
}
client := newClient(c.service, c.gitHostURL)
if c.githubListUserMigrations {
handleGithubListUserMigrations(client, c)
} else if c.githubCreateUserMigration {
handleGithubCreateUserMigration(client, c)
} else {
if err := handleGitRepositoryClone(client, c); err != nil {
return err
}
}
return nil
},
Commands: []*cli.Command{
{
Name: "init",
Usage: "Create a default gitbackup.yml configuration file",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "config",
Usage: "Path to config file (default: OS config directory)",
},
},
Action: func(cCtx *cli.Context) error {
return handleInitConfig(cCtx.String("config"))
},
},
{
Name: "validate",
Usage: "Validate the gitbackup.yml configuration file",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "config",
Usage: "Path to config file (default: OS config directory)",
},
},
Action: func(cCtx *cli.Context) error {
return handleValidateConfig(cCtx.String("config"))
},
},
},
}
if err := app.Run(os.Args); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
log.Fatal(err)
}
}