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
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)
}

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 (
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
}