• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang goptions.ParseAndFail函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: main

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

	if len(options.Verbs) == 0 {
		goptions.PrintHelp()
		os.Exit(2)
	}

	VERBOSITY = len(options.Verbosity)

	if cmd, found := commands[options.Verbs]; found {
		err := cmd(options)
		if err != nil {
			if !options.Quiet {
				fmt.Println("error:", err)
			}
			os.Exit(1)
		}
	}
}
开发者ID:suntong,项目名称:lang,代码行数:20,代码来源:CommandLineGoptions.go


示例17: main

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

	goriot.SetAPIKey(options.APIKey)

	session, err := mgo.Dial(options.MongoDB)
	if err != nil {
		log.Fatalf("Could not connect to MongoDB: %s", err)
	}
	db = session.DB("")

	r := httptools.NewRegexpSwitch(map[string]http.Handler{
		"/([a-z]+)/([0-9]+)/parse": httptools.L{
			httptools.SilentHandler(http.HandlerFunc(whitelistHandler)),
			httptools.L{
				httptools.SilentHandler(http.HandlerFunc(parseMatchHistory)),
				http.HandlerFunc(dumpMatchHistory),
			},
		},
		"/([a-z]+)/([0-9]+)": httptools.L{
			httptools.SilentHandler(http.HandlerFunc(whitelistHandler)),
			httptools.MethodSwitch{
				"POST": httptools.L{
					httptools.SilentHandler(http.HandlerFunc(parseMatchHistory)),
					http.HandlerFunc(saveMatchHistory),
				},
				"GET": httptools.L{
					httptools.SilentHandler(http.HandlerFunc(queryMatchHistory)),
					http.HandlerFunc(dumpMatchHistory),
				},
			},
		},
		"/.*": http.FileServer(http.Dir(options.StaticContent)),
	})

	addr := fmt.Sprintf("0.0.0.0:%d", options.Port)
	log.Printf("Starting webserver on %s...", addr)
	if err := http.ListenAndServe(addr, r); err != nil {
		log.Fatalf("Could not start webserver: %s", err)
	}
}
开发者ID:surma-dump,项目名称:lolkaiser,代码行数:41,代码来源:main.go


示例18: main

func main() {
	options := struct {
		Server   string        `goptions:"-s, --server, obligatory, description='Server to connect to'"`
		Password string        `goptions:"-p, --password, description='Don\\'t prompt for password'"`
		Timeout  time.Duration `goptions:"-t, --timeout, description='Connection timeout in seconds'"`
		Help     goptions.Help `goptions:"-h, --help, description='Show this help'"`

		goptions.Verbs
		Execute struct {
			Command string   `goptions:"--command, mutexgroup='input', description='Command to exectute', obligatory"`
			Script  *os.File `goptions:"--script, mutexgroup='input', description='Script to exectute', rdonly"`
		} `goptions:"execute"`
		Delete struct {
			Path  string `goptions:"-n, --name, obligatory, description='Name of the entity to be deleted'"`
			Force bool   `goptions:"-f, --force, description='Force removal'"`
		} `goptions:"delete"`
	}{ // Default values goes here
		Timeout: 10 * time.Second,
	}
	goptions.ParseAndFail(&options)
}
开发者ID:whf839,项目名称:goptions,代码行数:21,代码来源:readme_example.go


示例19: main

func main() {
	log.SetFlags(log.Ltime | log.Lshortfile)

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

	if len(options.Verbs) == 0 {
		goptions.PrintHelp()
		os.Exit(2)
	}

	VERBOSITY = len(options.Verbosity)

	messageIds = make(map[string]bool)
	messageFetchMode = options.Verbs == "fetch"
	if cmd, found := commands[options.Verbs]; found {
		err := cmd(options)
		check(err)
	}

}
开发者ID:suntong,项目名称:cloudmail,代码行数:21,代码来源:main.go


示例20: 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 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)
	zone := cli.New(api)

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

	case "list":
		zone.List()

	case "info":
		zone.Info(opts.Info.Zone)

	case "create":
		zone.Create(opts.Create.Name)

	case "delete":
		zone.Delete(opts.Delete.Zone)

	case "set":
		zone.Set(opts.Set.Domain, opts.Set.Zone)

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang goptions.PrintHelp函数代码示例发布时间:2022-05-28
下一篇:
Golang engine.Vector类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap