当前位置: 首页>>代码示例>>Golang>>正文


Golang goptions.ParseAndFail函数代码示例

本文整理汇总了Golang中github.com/voxelbrain/goptions.ParseAndFail函数的典型用法代码示例。如果您正苦于以下问题:Golang ParseAndFail函数的具体用法?Golang ParseAndFail怎么用?Golang ParseAndFail使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ParseAndFail函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: main

func main() {
	goptions.ParseAndFail(&options)

	log.Printf("Connecting to mongodb on %s...", options.MongoDB)
	session, err := mgo.Dial(options.MongoDB.String())
	if err != nil {
		log.Fatalf("Could not connect to %s: %s", options.MongoDB, err)
	}
	defer session.Close()
	db := session.DB("") // Use database specified in URL
	usermgr := &MongoUserManager{db.C("users")}
	domainmgr := &MongoDomainManager{db.C("domains")}

	mainrouter := mux.NewRouter()
	approuter := mainrouter.Host(options.Hostname).Subrouter()
	authrouter := approuter.PathPrefix("/auth").Subrouter()
	apirouter := approuter.PathPrefix("/api").Subrouter()

	setupAuthApps(authrouter, usermgr)
	setupApiApps(apirouter, domainmgr, usermgr)

	approuter.PathPrefix("/").Handler(http.FileServer(http.Dir(options.StaticDir)))
	mainrouter.PathPrefix("/").Handler(&Metapage{domainmgr})
	log.Printf("Running webserver...")
	log.Fatalf("Failed to run webserver: %s",
		http.ListenAndServe(options.ListenAddress.String(), mainrouter))
}
开发者ID:surma,项目名称:importalias,代码行数:27,代码来源:importalias.go

示例2: main

func main() {
	log.Infof("starting schema...")

	options := struct {
		Driver string `goptions:"-t,--type, obligatory, description='Type of database backend'"`
		DSN    string `goptions:"-d,--database, obligatory, description='DSN of the database backend'"`
	}{
	// No defaults
	}
	goptions.ParseAndFail(&options)

	database := &db.DB{
		Driver: options.Driver,
		DSN:    options.DSN,
	}

	log.Debugf("connecting to %s database at %s", database.Driver, database.DSN)
	if err := database.Connect(); err != nil {
		log.Errorf("failed to connect to %s database at %s: %s",
			database.Driver, database.DSN, err)
	}

	if err := database.Setup(); err != nil {
		log.Errorf("failed to set up schema in %s database at %s: %s",
			database.Driver, database.DSN, err)
		return
	}

	log.Infof("deployed schema version %d", db.CurrentSchema)
}
开发者ID:yacloud-io,项目名称:shield,代码行数:30,代码来源:main.go

示例3: main

func main() {
	opts := &Options{}
	goptions.ParseAndFail(opts)

	// Print version number and exit if the version flag is set
	if opts.Version {
		fmt.Printf("gandi-operation v%s\n", shared.VersionNumber)
		return
	}

	// Get gandi client
	client := shared.NewGandiClient(opts.ConfigPath, opts.Testing)

	// Create api and operation instances
	api := api.New(client)
	operation := cli.New(api)

	switch opts.Verbs {
	case "count":
		operation.Count()

	case "list":
		operation.List()

	case "info":
		operation.Info(opts.Info.Operation)

	case "cancel":
		operation.Cancel(opts.Cancel.Operation)

	default:
		goptions.PrintHelp()
	}
}
开发者ID:prasmussen,项目名称:gandi,代码行数:34,代码来源:gandi-operation.go

示例4: main

func main() {
	xlog.SetOutput(os.Stdout)

	options := struct {
		Topic   string `goptions:"--topic, description='Topic', obligatory"`
		Channel string `goptions:"--channel, description='Channel', obligatory"`
		Lookupd string `goptions:"--lookupd, description='lookupd address', obligatory"`
		DSN     string `goptions:"--dsn, description='MySQL DSN string', obligatory"`
	}{}

	goptions.ParseAndFail(&options)

	sqldb, err := sql.Open("mysql", options.DSN)
	if err != nil {
		xlog.Fatalf("sql.Open failed: %v", err)
	}

	r, err := nsq.NewReader(options.Topic, options.Channel)
	if err != nil {
		xlog.Fatalf("Opening reader for %s/%s failed: %v", options.Topic, options.Channel, err)
	}

	r.AddHandler(&Converter{DB: sqldb})

	if err := r.ConnectToLookupd(options.Lookupd); err != nil {
		xlog.Errorf("Connecting to %s failed: %v", options.Lookupd, err)
	}

	select {}
}
开发者ID:joinmytalk,项目名称:satsuma,代码行数:30,代码来源:pdfd.go

示例5: main

func main() {
	opts := &Options{}
	goptions.ParseAndFail(opts)

	// Print version number and exit if the version flag is set
	if opts.Version {
		fmt.Printf("gandi-domain-zone-record v%s\n", shared.VersionNumber)
		return
	}

	// Get gandi client
	client := shared.NewGandiClient(opts.ConfigPath, opts.Testing)

	// Create api and zone instances
	api := api.New(client)
	record := cli.New(api)

	switch opts.Verbs {
	case "count":
		record.Count(opts.Count.Zone, opts.Count.Version)

	case "list":
		record.List(opts.List.Zone, opts.List.Version)

	case "add":
		record.Add(opts.Add)

	case "delete":
		args := opts.Delete
		record.Delete(args.Zone, args.Version, args.Record)

	default:
		goptions.PrintHelp()
	}
}
开发者ID:prasmussen,项目名称:gandi,代码行数:35,代码来源:gandi-domain-zone-record.go

示例6: main

func main() {
	options := Options{}

	goptions.ParseAndFail(&options)

	if options.Version {
		fmt.Printf("github-release v%s\n", VERSION)
		return
	}

	if len(options.Verbs) == 0 {
		goptions.PrintHelp()
		return
	}

	VERBOSITY = len(options.Verbosity)

	if cmd, found := commands[options.Verbs]; found {
		err := cmd(options)
		if err != nil {
			if !options.Quiet {
				fmt.Fprintln(os.Stderr, "error:", err)
			}
			os.Exit(1)
		}
	}
}
开发者ID:DeadlyEmbrace,项目名称:github-release,代码行数:27,代码来源:github-release.go

示例7: main

func main() {
	opts := &Options{}
	goptions.ParseAndFail(opts)

	// Print version number and exit if the version flag is set
	if opts.Version {
		fmt.Printf("gandi-contact v%s\n", shared.VersionNumber)
		return
	}

	// Get gandi client
	client := shared.NewGandiClient(opts.ConfigPath, opts.Testing)

	// Create api and cli instances
	api := api.New(client)
	contact := cli.New(api)

	switch opts.Verbs {
	case "balance":
		contact.Balance()

	case "info":
		contact.Info(opts.Info.Contact)

	case "create":
		contact.Create(opts.Create)

	case "delete":
		contact.Delete(opts.Delete.Contact)

	default:
		goptions.PrintHelp()
	}
}
开发者ID:prasmussen,项目名称:gandi,代码行数:34,代码来源:gandi-contact.go

示例8: init

func init() {
	goptions.ParseAndFail(&options)
	options.OutputDir = filepath.Clean(options.OutputDir + "/iowhip_" + Timestamp)

	cleanupc := make(chan os.Signal)
	signal.Notify(cleanupc, syscall.SIGTERM, syscall.SIGKILL, syscall.SIGINT)
	go func() {
		<-cleanupc
		cleanup()
	}()
}
开发者ID:voxelbrain,项目名称:iowhip,代码行数:11,代码来源:iowhip.go

示例9: main

func main() {
	daddr, err := net.ResolveTCPAddr("tcp", "0.0.0.0:8080")
	if err != nil {
		log.Fatal(err)
	}

	options := struct {
		CityFiles     []string      `goptions:"-d, description='Data files to load'"`
		CountryNames  string        `goptions:"-c, description='CSV file holding country names'"`
		CountryShapes string        `goptions:"-c, description='CSV file holding country shapes'"`
		Help          goptions.Help `goptions:"-h, --help, description='Show this help'"`
		ListenAddr    *net.TCPAddr  `goptions:"-l, --listen, description='Listen address for HTTP server'"`
	}{
		CountryNames:  "data/countries_en.csv",
		CountryShapes: "data/countries.csv.bz2",
		ListenAddr:    daddr,
	}
	goptions.ParseAndFail(&options)

	rt_countries = rtreego.NewTree(2, 10, 20)
	_, err = load_freegeodb_countries_csv(rt_countries, options.CountryShapes)
	if err != nil {
		log.Fatal(err)
	}

	countries_exp, err = load_country_names(options.CountryNames)
	if err != nil {
		log.Fatal(err)
	}

	rt = rtreego.NewTree(2, 25, 50)
	total_loaded_cities := 0
	start_t := time.Now()
	for _, fname := range options.CityFiles {
		loaded, err := load_gisgraphy_cities_csv(rt, fname)
		if err != nil {
			log.Fatal(err)
		}
		total_loaded_cities += loaded
	}
	if total_loaded_cities > 0 {
		log.Println("Loaded", total_loaded_cities, "cities in", time.Now().Sub(start_t))
	}

	log.Println("Starting HTTP server on", options.ListenAddr)
	http.HandleFunc("/rg/", reverseGeocodingHandler)
	http.HandleFunc("/gj/", serveGeoJson)
	http.Handle("/", http.FileServer(http.Dir("html")))
	err = http.ListenAndServe(options.ListenAddr.String(), nil)
	if err != nil {
		log.Fatal(err)
	}
}
开发者ID:fg1,项目名称:mugiss,代码行数:53,代码来源:main.go

示例10: main

func main() {
	goptions.ParseAndFail(&options)

	for _, m := range options.Maps {
		h := m.Handler
		http.Handle(m.Path, http.StripPrefix(m.Path, h))
	}
	log.Printf("Starting webserver on %s...", options.Listen)
	err := http.ListenAndServe(options.Listen, nil)
	if err != nil {
		log.Fatalf("Could not start webserver: %s", err)
	}
}
开发者ID:surma,项目名称:phrank,代码行数:13,代码来源:phrank.go

示例11: main

func main() {

	options := struct {
		Zone  string        `goptions:"-z, --zone, description='The zone to use'"`
		Token string        `goptions:"--token, description='The token for the CF API'"`
		Email string        `goptions:"--email, description='The email for the CF API'"`
		Help  goptions.Help `goptions:"-h, --help, description='Show this help'"`

		goptions.Verbs
		Add struct {
			Content string `goptions:"-c, --content, obligatory, description='The content for the record'"`
			Name    string `goptions:"-n, --name, obligatory, description='The name of the record'"`
			Type    string `goptions:"-t, --type, description='The type of the record'"`
		} `goptions:"add"`

		Delete struct {
			Content          string `goptions:"-c, --content, obligatory, description='The content for the record'"`
			SkipConfirmation bool   `goptions:"-y, --yes, description='Skip confirmation'"`
		} `goptions:"delete"`
	}{
		Zone:  os.Getenv(CFZone),
		Email: os.Getenv(CFEmail),
		Token: os.Getenv(CFToken),
	}

	goptions.ParseAndFail(&options)

	opts := Options{
		Email: options.Email,
		Token: options.Token,
		Zone:  options.Zone,
	}

	switch {
	case options.Verbs == "add":
		opts.Content = options.Add.Content
		opts.Name = options.Add.Name
		opts.Type = options.Add.Type

		addRecord(&opts)
	case options.Verbs == "delete":
		opts.Content = options.Delete.Content
		opts.SkipConfirm = options.Delete.SkipConfirmation

		deleteRecords(&opts)
	}
}
开发者ID:floriank,项目名称:cloudflare,代码行数:47,代码来源:command.go

示例12: init

func init() {
	options = Options{
		Env: "dev",
	}
	goptions.ParseAndFail(&options)

	if len(options.RootDir) > 0 {
		rootDir = options.RootDir
	} else {
		var err error
		if rootDir, err = filepath.Abs(fmt.Sprintf("%s/../resources/", filepath.Dir(os.Args[0]))); err != nil {
			panic(err)
		}
		options.RootDir = rootDir
	}

	configPath := fmt.Sprintf("%s/config.%s.yml", RootDir(), options.Env)

	config = new(Config)
	if cfgBytes, err := ioutil.ReadFile(configPath); err != nil {
		panic(err)
	} else {
		err := yaml.Unmarshal([]byte(cfgBytes), &config)
		if err != nil {
			panic(err)
		}
	}

	switch GetConfig().Logger.Writer {
	case LOGGER_WRITER_STD_OUT:
		logger = log.NewLogger(log.NewConcurrentWriter(os.Stdout), GetConfig().Logger.Namespace)
	case LOGGER_WRITER_SYSLOG:
		writer, _ := syslog.New(syslog.LOG_DEBUG|syslog.LOG_LOCAL0, GetConfig().Logger.Namespace)
		logger = log.NewLogger(log.NewConcurrentWriter(writer), GetConfig().Logger.Namespace)
	default:
		panic(errors.New(fmt.Sprintf("Unknown logger writer %s", GetConfig().Logger.Writer)))
	}
	logger.SetLevel(log.LevelAtoi[GetConfig().Logger.Level])
	GetLogger().Info("Initializing application", "ver", VERSION)

	hasher := md5.New()
	hasher.Write([]byte(time.Now().Format("2006/01/02 - 15:04:05")))
	instanceId = hex.EncodeToString(hasher.Sum(nil))[:5]
	GetLogger().Info("Initialized application", "instance ID", instanceId)
}
开发者ID:vgarvardt,项目名称:incrementoring,代码行数:45,代码来源:init.go

示例13: main

func main() {
	goptions.ParseAndFail(&options)

	// Use current directory by default
	if options.RootDir == "" {
		options.RootDir = os.Getenv("PWD")
	}

	options.RootDir = strings.TrimRight(options.RootDir, "/")

	fmt.Printf("%+v\n", options)

	err := rename(options.RootDir, options.OldPattern, options.NewPattern)

	if err != nil {
		fmt.Println(err)
	}
}
开发者ID:enzochiau,项目名称:rename_uvc,代码行数:18,代码来源:rename_uvc.go

示例14: main

// Application entry point
func main() {

	fmt.Printf("\n%s (%s) %s\n\n", APP_TITLE, APP_NAME, APP_VERSION)

	// Set the default values for the command line options
	opt = new(Options)
	opt.Server = DEFAULT_SERVER
	opt.Format = FORMAT_ALL
	opt.BatchSize = BATCH_SIZE

	goptions.ParseAndFail(opt)

	// Lets make sure that the users input file actually exists
	if _, err := os.Stat(opt.InputFile); os.IsNotExist(err) {
		log.Fatal("Input file does not exist")
	}

	processInputFile()
}
开发者ID:infoassure,项目名称:nsrlc,代码行数:20,代码来源:main.go

示例15: main

func main() {
	goptions.ParseAndFail(&options)
	//fmt.Printf("] %#v\r\n", options)

	if len(options.Verbs) == 0 {
		fmt.Printf("%s%s \n      built on %s\n\n", progname, progdesc, buildTime)
		goptions.PrintHelp()
		os.Exit(2)
	}

	VERBOSITY = len(options.Verbosity)

	configGet(os.Args[0])

	if cmd, found := commands[options.Verbs]; found {
		err := cmd(options)
		check(err)
	}
}
开发者ID:AntonioSun,项目名称:lta,代码行数:19,代码来源:lta-main.go


注:本文中的github.com/voxelbrain/goptions.ParseAndFail函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。