llconsolidate/options.go

52 lines
1.2 KiB
Go
Raw Normal View History

2015-11-20 17:11:36 +01:00
// options
package main
import (
"flag"
"fmt"
"gopkg.in/mgo.v2"
"log"
"os"
"path"
"path/filepath"
"time"
)
type Options struct {
MongoSrc string
MongoDst string
mdbSrc *mgo.Session
mdbDst *mgo.Session
ll *mgo.Collection
lc *mgo.Collection
StartDate string
Duration time.Duration
Interval time.Duration
LogFile string
Version bool
Debug bool
}
func usage() {
fmt.Println("Usage: lastlogin_consolidate -ms <mongo source mongodb://IP:PORT> -md <mongo destination mongodb://IP:PORT> -l <logfile> -d <date> -dd <duration> -i <interval> -v\n")
os.Exit(0)
}
func init() {
current, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
log.Fatal(err)
}
opts.LogFile = path.Join(current, opts.LogFile)
flag.StringVar(&opts.MongoSrc, "ms", opts.MongoSrc, "Mongodb Source")
flag.StringVar(&opts.MongoDst, "md", "", "Mongodb Destination")
flag.StringVar(&opts.LogFile, "l", opts.LogFile, "Logs filename")
flag.StringVar(&opts.StartDate, "d", opts.StartDate, "Date")
flag.DurationVar(&opts.Duration, "dd", opts.Duration, "Duration")
flag.DurationVar(&opts.Interval, "i", opts.Interval, "Duration")
flag.BoolVar(&opts.Version, "v", false, "Version")
flag.BoolVar(&opts.Debug, "debug", false, "Debug")
}