11package main
22
33import (
4+ "flag"
45 gitbackup "git-backup"
56 "log"
67 "os"
78 "path/filepath"
89)
910
11+ var configFilePath = flag .String ("config.file" , "git-backup.yml" , "The path to your config file." )
12+ var targetPath = flag .String ("backup.path" , "backup" , "The target path to the backup folder." )
13+
1014func main () {
15+ flag .Parse ()
16+
1117 config := loadConfig ()
1218 for _ , source := range config .GetSources () {
1319 sourceName := source .GetName ()
@@ -23,7 +29,7 @@ func main() {
2329 }
2430 for _ , repo := range repos {
2531 log .Printf ("Discovered %s" , repo .FullName )
26- targetPath := filepath .Join ("backup" , sourceName , repo .FullName )
32+ targetPath := filepath .Join (* targetPath , sourceName , repo .FullName )
2733 err := os .MkdirAll (targetPath , os .ModePerm )
2834 if err != nil {
2935 log .Printf ("Failed to create directory: %s" , err )
@@ -34,14 +40,13 @@ func main() {
3440 log .Printf ("Failed to clone: %s" , err )
3541 os .Exit (100 )
3642 }
37-
3843 }
3944 }
4045}
4146
4247func loadConfig () gitbackup.Config {
4348 // try config file in working directory
44- config , err := gitbackup .LoadFile ("./git-backup.yml" )
49+ config , err := gitbackup .LoadFile (* configFilePath )
4550 if os .IsNotExist (err ) {
4651 log .Println ("No config file found. Exiting..." )
4752 os .Exit (1 )
@@ -50,4 +55,4 @@ func loadConfig() gitbackup.Config {
5055 os .Exit (1 )
5156 }
5257 return config
53- }
58+ }
0 commit comments