本文整理汇总了Golang中github.com/voxelbrain/goptions.PrintHelp函数的典型用法代码示例。如果您正苦于以下问题:Golang PrintHelp函数的具体用法?Golang PrintHelp怎么用?Golang PrintHelp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PrintHelp函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: 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-version 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)
version := cli.New(api)
switch opts.Verbs {
case "count":
version.Count(opts.Count.Zone)
case "list":
version.List(opts.List.Zone)
case "new":
version.New(opts.New.Zone, opts.New.Version)
case "delete":
version.Delete(opts.Delete.Zone, opts.Delete.Version)
case "set":
version.Set(opts.Set.Zone, opts.Set.Version)
default:
goptions.PrintHelp()
}
}
开发者ID:prasmussen,项目名称:gandi,代码行数:37,代码来源:gandi-domain-zone-version.go
示例17: Run
content := fmt.Sprintf(format, args...)
lines := strings.Split(content, "\n")
for i, line := range lines {
lines[i] = "DEBUG> " + line
}
content = strings.Join(lines, "\n")
fmt.Fprintf(stderr, "%s\n", content)
}
}
var stdout = os.Stdout
var stderr = os.Stderr
var usage = func(err error) {
fmt.Fprintf(stderr, "%s\n", err.Error())
goptions.PrintHelp()
}
var exit = func(code int) {
os.Exit(code)
}
func Run(p Plugin) {
var code int
var action string
opts, err := getPluginOptions()
if err != nil {
usage(err)
code = USAGE
} else {
action = string(opts.Action)
开发者ID:starkandwayne,项目名称:shield,代码行数:31,代码来源:plugin.go
示例18: Usage
// Display the usage message and exit
func Usage() {
goptions.PrintHelp()
os.Exit(1)
}
开发者ID:angst,项目名称:roscoe,代码行数:5,代码来源:osc.go
示例19: Main
// Main defines the primary handler for transforming an application into a Sparta package. The
// serviceName is used to uniquely identify your service within a region and will
// be used for subsequent updates. For provisioning, ensure that you've
// properly configured AWS credentials for the golang SDK.
// See http://docs.aws.amazon.com/sdk-for-go/api/aws/defaults.html#DefaultChainCredentials-constant
// for more information.
func Main(serviceName string, serviceDescription string, lambdaAWSInfos []*LambdaAWSInfo, api *API) error {
// We need to be able to provision an IAM role that has capabilities to
// manage the other sources. That'll give us the role arn to use in the custom
// resource execution.
options := struct {
Noop bool `goptions:"-n, --noop, description='Dry-run behavior only (do not provision stack)'"`
LogLevel string `goptions:"-l, --level, description='Log level [panic, fatal, error, warn, info, debug]'"`
Help goptions.Help `goptions:"-h, --help, description='Show this help'"`
Verb goptions.Verbs
Provision struct {
S3Bucket string `goptions:"-b,--s3Bucket, description='S3 Bucket to use for Lambda source', obligatory"`
} `goptions:"provision"`
Delete struct {
} `goptions:"delete"`
Execute struct {
Port int `goptions:"-p,--port, description='Alternative port for HTTP binding (default=9999)'"`
SignalParentPID int `goptions:"-s,--signal, description='Process ID to signal with SIGUSR2 once ready'"`
} `goptions:"execute"`
Describe struct {
OutputFile string `goptions:"-o,--out, description='Output file for HTML description', obligatory"`
} `goptions:"describe"`
Explore struct {
Port int `goptions:"-p,--port, description='Alternative port for HTTP binding (default=9999)'"`
} `goptions:"explore"`
}{ // Default values goes here
LogLevel: "info",
}
goptions.ParseAndFail(&options)
logger, err := NewLogger(options.LogLevel)
if err != nil {
goptions.PrintHelp()
os.Exit(1)
}
logger.WithFields(logrus.Fields{
"Option": options.Verb,
"Version": SpartaVersion,
}).Info("Welcome to Sparta")
switch options.Verb {
case "provision":
logger.Formatter = new(logrus.TextFormatter)
err = Provision(options.Noop, serviceName, serviceDescription, lambdaAWSInfos, api, options.Provision.S3Bucket, nil, logger)
case "execute":
logger.Formatter = new(logrus.JSONFormatter)
err = Execute(lambdaAWSInfos, options.Execute.Port, options.Execute.SignalParentPID, logger)
case "delete":
logger.Formatter = new(logrus.TextFormatter)
err = Delete(serviceName, logger)
case "explore":
logger.Formatter = new(logrus.TextFormatter)
err = Explore(lambdaAWSInfos, options.Explore.Port, logger)
case "describe":
logger.Formatter = new(logrus.TextFormatter)
fileWriter, err := os.Create(options.Describe.OutputFile)
if err != nil {
return fmt.Errorf("Failed to open %s output. Error: %s", options.Describe.OutputFile, err)
}
defer fileWriter.Close()
err = Describe(serviceName, serviceDescription, lambdaAWSInfos, api, fileWriter, logger)
default:
goptions.PrintHelp()
err = fmt.Errorf("Unsupported subcommand: %s", string(options.Verb))
}
if nil != err {
logger.Error(err)
}
return err
}
开发者ID:jbrook,项目名称:Sparta,代码行数:76,代码来源:sparta.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("gdrive v%s\n", VersionNumber)
return
}
// Get authorized drive client
drive, err := gdrive.New(opts.AppPath, opts.Advanced, true)
if err != nil {
writeError("An error occurred creating Drive client: %v\n", err)
}
switch opts.Verbs {
case "list":
args := opts.List
err = cli.List(drive, args.Query, args.TitleFilter, args.MaxResults, args.SharedStatus, args.NoHeader, args.IncludeDocs, args.SizeInBytes)
case "info":
err = cli.Info(drive, opts.Info.FileId, opts.Info.SizeInBytes)
case "folder":
args := opts.Folder
err = cli.Folder(drive, args.Title, args.ParentId, args.Share)
case "upload":
args := opts.Upload
// Set custom chunksize if given
if args.ChunkSize >= (1 << 18) {
googleapi.SetChunkSize(args.ChunkSize)
}
if args.Stdin {
err = cli.UploadStdin(drive, os.Stdin, args.Title, args.ParentId, args.Share, args.MimeType, args.Convert)
} else {
err = cli.Upload(drive, args.File, args.Title, args.ParentId, args.Share, args.MimeType, args.Convert)
}
case "download":
args := opts.Download
if args.Pop {
err = cli.DownloadLatest(drive, args.Stdout, args.Format, args.Force)
} else {
err = cli.Download(drive, args.FileId, args.Stdout, false, args.Format, args.Force)
}
case "delete":
err = cli.Delete(drive, opts.Delete.FileId)
case "share":
err = cli.Share(drive, opts.Share.FileId)
case "unshare":
err = cli.Unshare(drive, opts.Unshare.FileId)
case "url":
if opts.Url.Download {
fmt.Println(util.DownloadUrl(opts.Url.FileId))
} else {
fmt.Println(util.PreviewUrl(opts.Url.FileId))
}
case "quota":
err = cli.Quota(drive, opts.Quota.SizeInBytes)
default:
goptions.PrintHelp()
}
if err != nil {
writeError("%s", err)
}
}
开发者ID:seamusburke54,项目名称:gdrive,代码行数:77,代码来源:drive.go
注:本文中的github.com/voxelbrain/goptions.PrintHelp函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论