1
0
Fork 0

Sync script

This commit is contained in:
Gregory Eremin 2015-03-29 00:06:01 +07:00
parent 71f5781c86
commit 86d503d622
3 changed files with 41 additions and 8 deletions

View File

@ -1,12 +1,16 @@
package main package main
import ( import (
"flag"
"github.com/localhots/empact/config" "github.com/localhots/empact/config"
"github.com/localhots/empact/db" "github.com/localhots/empact/db"
"github.com/localhots/empact/server" "github.com/localhots/empact/server"
) )
func main() { func main() {
flag.Parse()
config.Load()
if err := db.Connect(config.C().DatabaseURI); err != nil { if err := db.Connect(config.C().DatabaseURI); err != nil {
panic(err) panic(err)
} }

28
bin/sync.go Normal file
View File

@ -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 {}
}

View File

@ -22,20 +22,16 @@ type (
) )
var ( var (
path string
conf Config conf Config
) )
// Config is immutable and is always returned by value func init() {
func C() Config { flag.StringVar(&path, "config", "config.json", "Path to configuration file")
return conf
} }
func init() { func Load() {
var err error var err error
var path string
flag.StringVar(&path, "config", "config.json", "Path to configuration file")
flag.Parse()
var fd *os.File var fd *os.File
if fd, err = os.Open(path); err != nil { if fd, err = os.Open(path); err != nil {
panic(err) panic(err)
@ -51,3 +47,8 @@ func init() {
log.SetOutput(os.Stderr) log.SetOutput(os.Stderr)
log.SetFlags(log.Ldate | log.Ltime) log.SetFlags(log.Ldate | log.Ltime)
} }
// Config is immutable and is always returned by value
func C() Config {
return conf
}