package main import ( "errors" "strings" log "github.com/Sirupsen/logrus" flag "github.com/spf13/pflag" ) // global config, gets overwritten by main var _conf Config func init() { // overwrites unhelpful error message flag.ErrHelp = errors.New("") // we need to parse the config because of log level setting configFile := flag.StringP("config", "c", "", "path to config file") debug := flag.BoolP("debug", "d", false, "debug outputs") verbose := flag.BoolP("verbose", "v", false, "same as --debug") silent := flag.BoolP("silent", "s", false, "suppress outputs except warnings") loglevel_f := flag.StringP("loglevel", "l", "Warn", `sets log level, can be "Warn", "Info" or "Debug"`) flag.Bool("list-shops", false, `lists all crawlable shops`) shopids_f := flag.StringP("restrict-shops", "r", "", `comma separated list of shop ids, crawls only these`) flag.Parse() loglevel := strings.ToLower(*loglevel_f) if *debug || *verbose || loglevel == "debug" { log.SetLevel(log.DebugLevel) } else if loglevel == "info" { log.SetLevel(log.InfoLevel) } else { log.SetLevel(log.WarnLevel) } if *silent { log.SetLevel(log.WarnLevel) } _conf.parseConfig(*configFile) if _conf.Debug && !*silent { log.SetLevel(log.DebugLevel) } if "" != *shopids_f { _conf.ShopIDs = strings.Split(*shopids_f, ",") } }