From 86d503d62226e0334e1a4cc029791946e7d7148b Mon Sep 17 00:00:00 2001 From: Gregory Eremin Date: Sun, 29 Mar 2015 00:06:01 +0700 Subject: [PATCH] Sync script --- bin/empact-server.go | 4 ++++ bin/sync.go | 28 ++++++++++++++++++++++++++++ config/config.go | 17 +++++++++-------- 3 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 bin/sync.go diff --git a/bin/empact-server.go b/bin/empact-server.go index 3a0fac3..6b35788 100644 --- a/bin/empact-server.go +++ b/bin/empact-server.go @@ -1,12 +1,16 @@ package main import ( + "flag" + "github.com/localhots/empact/config" "github.com/localhots/empact/db" "github.com/localhots/empact/server" ) func main() { + flag.Parse() + config.Load() if err := db.Connect(config.C().DatabaseURI); err != nil { panic(err) } diff --git a/bin/sync.go b/bin/sync.go new file mode 100644 index 0000000..02b550e --- /dev/null +++ b/bin/sync.go @@ -0,0 +1,28 @@ +package main + +import ( + "flag" + "fmt" + + "github.com/localhots/empact/config" + "github.com/localhots/empact/db" + "github.com/localhots/empact/task" +) + +func main() { + var token string + flag.StringVar(&token, "token", "", "GitHub access token") + flag.Parse() + config.Load() + if token == "" { + fmt.Println("Access token is required") + return + } + + if err := db.Connect(config.C().DatabaseURI); err != nil { + panic(err) + } + + task.SyncUserOrgs(token) + select {} +} diff --git a/config/config.go b/config/config.go index 74a7d32..56b3d21 100644 --- a/config/config.go +++ b/config/config.go @@ -22,20 +22,16 @@ type ( ) var ( + path string conf Config ) -// Config is immutable and is always returned by value -func C() Config { - return conf +func init() { + flag.StringVar(&path, "config", "config.json", "Path to configuration file") } -func init() { +func Load() { var err error - var path string - flag.StringVar(&path, "config", "config.json", "Path to configuration file") - flag.Parse() - var fd *os.File if fd, err = os.Open(path); err != nil { panic(err) @@ -51,3 +47,8 @@ func init() { log.SetOutput(os.Stderr) log.SetFlags(log.Ldate | log.Ltime) } + +// Config is immutable and is always returned by value +func C() Config { + return conf +}