File tree Expand file tree Collapse file tree 3 files changed +15
-4
lines changed Expand file tree Collapse file tree 3 files changed +15
-4
lines changed Original file line number Diff line number Diff line change 6
6
"log"
7
7
"os"
8
8
"path/filepath"
9
+ "time"
9
10
)
10
11
11
12
var configFilePath = flag .String ("config.file" , "git-backup.yml" , "The path to your config file." )
@@ -15,7 +16,14 @@ func main() {
15
16
flag .Parse ()
16
17
17
18
config := loadConfig ()
18
- for _ , source := range config .GetSources () {
19
+ sources := config .GetSources ()
20
+ if len (sources ) == 0 {
21
+ log .Printf ("Found a config file at [%s] but detected no sources. Are you sure the file is properly formed?" , * configFilePath )
22
+ os .Exit (111 )
23
+ }
24
+ repoCount := 0
25
+ backupStart := time .Now ()
26
+ for _ , source := range sources {
19
27
sourceName := source .GetName ()
20
28
log .Printf ("=== %s ===" , sourceName )
21
29
if err := source .Test (); err != nil {
@@ -41,7 +49,9 @@ func main() {
41
49
os .Exit (100 )
42
50
}
43
51
}
52
+ repoCount ++
44
53
}
54
+ log .Printf ("Backed up %d repositories in %s" , repoCount , time .Now ().Sub (backupStart ))
45
55
}
46
56
47
57
func loadConfig () gitbackup.Config {
Original file line number Diff line number Diff line change 1
1
package git_backup
2
2
3
3
import (
4
- "gopkg.in/yaml.v2 "
4
+ "gopkg.in/yaml.v3 "
5
5
"io"
6
6
"os"
7
7
)
@@ -54,7 +54,7 @@ func LoadFile(path string) (out Config, err error) {
54
54
55
55
func LoadReader (reader io.Reader ) (out Config , err error ) {
56
56
dec := yaml .NewDecoder (reader )
57
- dec .SetStrict (true )
57
+ dec .KnownFields (true )
58
58
err = dec .Decode (& out )
59
59
out .setDefaults ()
60
60
return
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ require (
7
7
github.com/google/go-github/v43 v43.0.0
8
8
github.com/xanzy/go-gitlab v0.60.0
9
9
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c
10
- gopkg.in/yaml.v2 v2.4.0
10
+ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
11
11
)
12
12
13
13
require (
@@ -34,4 +34,5 @@ require (
34
34
google.golang.org/appengine v1.6.7 // indirect
35
35
google.golang.org/protobuf v1.27.1 // indirect
36
36
gopkg.in/warnings.v0 v0.1.2 // indirect
37
+ gopkg.in/yaml.v2 v2.4.0 // indirect
37
38
)
You can’t perform that action at this time.
0 commit comments