// options package main import ( "flag" "fmt" "log" "os" "path" "path/filepath" "time" ) // Options structure type Options struct { CurrentPath string Exe string LogFile string ConfigFile string Timeout time.Duration MaxLogins int Debug bool Version bool Bulk bool Month string Hostname string Pidfile string } var ( opts = Options{ LogFile: "log/llmongo.log", MaxLogins: 100, } ) func usage() { fmt.Println("Usage: llmongo -m -r -l -T -H -v") fmt.Println() os.Exit(0) } func init() { var err error opts.CurrentPath, err = filepath.Abs(filepath.Dir(os.Args[0])) if err != nil { log.Fatal(err) } opts.LogFile = path.Join(opts.CurrentPath, opts.LogFile) opts.Pidfile = path.Join(opts.CurrentPath, "run", path.Base(os.Args[0])+".pid") opts.Exe = path.Base(os.Args[0]) flag.StringVar(&opts.Hostname, "H", "", "hostname") flag.StringVar(&dbs.MongoURI, "m", "", "Mongodb URI") flag.StringVar(&dbs.MongoDB, "md", dbs.MongoDB, "Mongodb Database") flag.StringVar(&dbs.RethinkURI, "r", "", "RethinkDB URI") flag.StringVar(&dbs.RethinkDB, "rd", dbs.RethinkDB, "Rethinkdb Database") flag.StringVar(&opts.LogFile, "l", opts.LogFile, "Logs filename") flag.IntVar(&opts.MaxLogins, "L", opts.MaxLogins, "Max lastlogins") flag.BoolVar(&opts.Version, "v", false, "Version") flag.DurationVar(&opts.Timeout, "T", 0, "Running timeout") flag.BoolVar(&opts.Debug, "D", false, "Debug") flag.BoolVar(&opts.Bulk, "B", false, "Bulk") flag.StringVar(&opts.Pidfile, "p", opts.Pidfile, "pid file") }