當前位置: 首頁>>代碼示例>>Golang>>正文


Golang goptions.PrintHelp函數代碼示例

本文整理匯總了Golang中github.com/voxelbrain/goptions.PrintHelp函數的典型用法代碼示例。如果您正苦於以下問題:Golang PrintHelp函數的具體用法?Golang PrintHelp怎麽用?Golang PrintHelp使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了PrintHelp函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: main

func main() {
	var opts ShieldAgentOpts
	opts.Log = "Info"
	if err := goptions.Parse(&opts); err != nil {
		fmt.Printf("%s\n", err)
		goptions.PrintHelp()
		return
	}
	if opts.Help {
		goptions.PrintHelp()
		os.Exit(0)
	}
	if opts.Version {
		if Version == "" {
			fmt.Printf("shield-agent (development)%s\n", Version)
		} else {
			fmt.Printf("shield-agent v%s\n", Version)
		}
		os.Exit(0)
	}
	if opts.ConfigFile == "" {
		fmt.Fprintf(os.Stderr, "You must specify a configuration file via `--config`\n")
		os.Exit(1)
	}

	log.SetupLogging(log.LogConfig{Type: "console", Level: opts.Log})
	log.Infof("starting agent")

	ag := agent.NewAgent()
	if err := ag.ReadConfig(opts.ConfigFile); err != nil {
		log.Errorf("configuration failed: %s", err)
		return
	}
	ag.Run()
}
開發者ID:starkandwayne,項目名稱:shield,代碼行數:35,代碼來源:main.go

示例2: 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

示例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() {
	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

示例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: init

func init() {
	err := goptions.Parse(&options)
	if err != nil || len(options.Remainder) <= 0 || len(options.Verbs) <= 0 {
		if err != goptions.ErrHelpRequest && err != nil {
			log.Printf("Error: %s", err)
		}
		goptions.PrintHelp()
		os.Exit(1)
	}
}
開發者ID:niilo,項目名稱:s3put,代碼行數:10,代碼來源:s3put.go

示例7: main

func main() {
	config, err := parseConfig()
	if err != nil {
		log.Fatalf("Could not parse config: %s", err)
	}

	switch options.Verbs {
	case "list":
		fmt.Println("Worlds:")
		for _, worldpath := range config.Worlds() {
			world := config.World(worldpath)
			fmt.Printf("\t%s (Depth: %d)\n", worldpath, world.ZoomLevels())
		}
	case "remove":
		for _, worldname := range options.Remove.Worlds {
			world := config.World(worldname)
			newzoom := world.ZoomLevels() - options.Remove.Num
			filepath.Walk(world.Path(), func(path string, fi os.FileInfo, err error) error {
				if fi.IsDir() {
					return nil
				}
				pe := strings.Split(path, "/")
				zoomLevel := len(pe)
				if zoomLevel > newzoom {
					log.Printf("Removing %s...", path)
					err := os.Remove(path)
					if err != nil {
						log.Printf("Could not delete %s: %s", path, err)
					}
				}
				return nil
			})
			world.SetZoomLevels(newzoom)
		}
		f, err := os.Create(CONFIG_FILE)
		if err != nil {
			log.Fatalf("Could not open config file %s for writing: %s", CONFIG_FILE, err)
		}
		defer f.Close()
		io.WriteString(f, "var overviewerConfig = ")
		enc := json.NewEncoder(f)
		enc.Encode(config)
	default:
		goptions.PrintHelp()
		return
	}
}
開發者ID:surma-dump,項目名稱:overviewer-zoomreduce,代碼行數:47,代碼來源:zoomreduce.go

示例8: main

func main() {
	err := goptions.Parse(&options)
	if err != nil || (len(options.FormatFile) <= 0 && len(options.FormatString) <= 0) {
		if err == nil {
			err = fmt.Errorf("One of --format-file and --format-string must be specified")
		}
		fmt.Printf("Error: %s\n", err)
		goptions.PrintHelp()
		fmt.Println("Formatters:")
		for name, format := range Formats {
			fmt.Printf("\t\"%s\": %s\n", name, format.Description)
		}
		fmt.Printf("Version %s\n", VERSION)
		return
	}

	format, ok := Formats[options.Format]
	if !ok {
		log.Fatalf("Unknown format %s", options.Format)
	}

	f, err := format.Compiler(formatString())
	if err != nil {
		log.Fatalf("Template invalid: %s", err)
	}

	dec := json.NewDecoder(os.Stdin)
	logFn := NewLogFn(options.Continue)
	for {
		var input interface{}
		err := dec.Decode(&input)
		if err == io.EOF {
			break
		}
		if err != nil {
			log.Fatalf("Could not decode input: %s", err)
			continue
		}
		err = f.Execute(os.Stdout, input)
		if err != nil {
			logFn("Could not apply input to template: %s", err)
			continue
		}
		io.WriteString(os.Stdout, "\n")
	}
}
開發者ID:aaronsw,項目名稱:jsonformat,代碼行數:46,代碼來源:jsonformat.go

示例9: main

func main() {
	var opts ShieldAgentOpts
	opts.Log = "Info"
	if err := goptions.Parse(&opts); err != nil {
		fmt.Printf("%s\n", err)
		goptions.PrintHelp()
		return
	}

	log.SetupLogging(log.LogConfig{Type: "console", Level: opts.Log})
	log.Infof("starting agent")

	ag := agent.NewAgent()
	if err := ag.ReadConfig(opts.ConfigFile); err != nil {
		log.Errorf("configuration failed: %s", err)
		return
	}
	ag.Run()
}
開發者ID:yacloud-io,項目名稱:shield,代碼行數:19,代碼來源:main.go

示例10: 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

示例11: 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

示例12: 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

示例13: 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

示例14: 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)

	if cmd, found := commands[options.Verbs]; found {
		err := cmd()
		if err != nil {
			if !options.Quiet {
				fmt.Printf("%s error: %v", progname, err)
			}
			os.Exit(1)
		}
	}
}
開發者ID:AntonioSun,項目名稱:wts,代碼行數:22,代碼來源:main.go

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

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

	case "list":
		domain.List()

	case "info":
		domain.Info(opts.Info.Domain)

	case "available":
		domain.Available(opts.Available.Domain)

	case "create":
		args := opts.Create
		domain.Create(args.Domain, args.Contact, args.Years)

	default:
		goptions.PrintHelp()
	}
}
開發者ID:prasmussen,項目名稱:gandi,代碼行數:38,代碼來源:gandi-domain.go


注:本文中的github.com/voxelbrain/goptions.PrintHelp函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。