-
-
Notifications
You must be signed in to change notification settings - Fork 16
feat: improve flags parsing #461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ package main | |
| import ( | ||
| "context" | ||
| "flag" | ||
| "fmt" | ||
| "log" | ||
| "math/rand" | ||
| "net/http" | ||
|
|
@@ -13,6 +14,7 @@ import ( | |
| "berty.tech/yolo/v2/go/pkg/bintray" | ||
| "go.uber.org/zap" | ||
| "golang.org/x/oauth2" | ||
| "moul.io/climan" | ||
| "moul.io/hcfilters" | ||
| "moul.io/zapconfig" | ||
|
|
||
|
|
@@ -25,19 +27,23 @@ import ( | |
| _ "github.com/jinzhu/gorm/dialects/sqlite" | ||
| circleci "github.com/jszwedko/go-circleci" | ||
| "github.com/peterbourgon/diskv" | ||
| ff "github.com/peterbourgon/ff/v2" | ||
| "github.com/peterbourgon/ff/v2/ffcli" | ||
| ff "github.com/peterbourgon/ff/v3" | ||
| ) | ||
|
|
||
| var ( | ||
| verbose bool | ||
| logFormat string | ||
| dbStorePath string | ||
| withPreloading bool | ||
| ) | ||
| type flagsBuilder func(fs *flag.FlagSet) | ||
|
|
||
| type GlobalOptions struct { | ||
| verbose bool | ||
| logFormat string | ||
| dbStorePath string | ||
|
|
||
| server server | ||
| } | ||
|
|
||
| var optsGlobal = &GlobalOptions{} | ||
|
Doozers marked this conversation as resolved.
Outdated
|
||
|
|
||
| func main() { | ||
| err := yolo(os.Args) | ||
| err := yolo(os.Args[1:]) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you check how things are going when you run
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| if err != nil { | ||
| log.Fatalf("err: %+v", err) | ||
| os.Exit(1) | ||
|
|
@@ -49,25 +55,33 @@ func yolo(args []string) error { | |
| rootFlagSet := flag.NewFlagSet("yolo", flag.ExitOnError) | ||
| rand.Seed(time.Now().UnixNano()) | ||
| rootFlagSet.SetOutput(os.Stderr) | ||
| rootFlagSet.BoolVar(&verbose, "v", false, "increase log verbosity") | ||
| rootFlagSet.StringVar(&logFormat, "log-format", "console", strings.Join(zapconfig.AvailablePresets, ", ")) | ||
|
|
||
| root := &ffcli.Command{ | ||
| ShortUsage: `server [flags] <subcommand>`, | ||
| FlagSet: rootFlagSet, | ||
| Subcommands: []*ffcli.Command{ | ||
| serverCommand(), | ||
| dumpObjectsCommand(), | ||
| infoCommand(), | ||
| treeCommand(), | ||
|
|
||
| commonFlagsBuilder := func(fs *flag.FlagSet) { | ||
| fs.BoolVar(&optsGlobal.verbose, "v", false, "increase log verbosity") | ||
| fs.StringVar(&optsGlobal.logFormat, "log-format", "console", strings.Join(zapconfig.AvailablePresets, ", ")) | ||
| fs.StringVar(&optsGlobal.dbStorePath, "db-path", ":memory:", "DB Store path") | ||
| } | ||
|
|
||
| root := &climan.Command{ | ||
| ShortUsage: `server [flags] <subcommand>`, | ||
| FlagSetBuilder: commonFlagsBuilder, | ||
| Subcommands: []*climan.Command{ | ||
| serverCommand(commonFlagsBuilder), | ||
| dumpObjectsCommand(commonFlagsBuilder), | ||
| infoCommand(commonFlagsBuilder), | ||
| treeCommand(commonFlagsBuilder), | ||
| }, | ||
| Options: []ff.Option{ff.WithEnvVarNoPrefix()}, | ||
| FFOptions: []ff.Option{ff.WithEnvVarNoPrefix()}, | ||
| Exec: func(_ context.Context, _ []string) error { | ||
| return flag.ErrHelp | ||
| }, | ||
| } | ||
|
|
||
| return root.ParseAndRun(context.Background(), os.Args[1:]) | ||
| if err := root.Parse(args); err != nil { | ||
| return fmt.Errorf("parse error: %w", err) | ||
| } | ||
|
|
||
| return root.Run(context.Background()) | ||
| } | ||
|
|
||
| func bintrayClientFromArgs(username, token string, logger *zap.Logger) (*bintray.Client, error) { | ||
|
|
||

Uh oh!
There was an error while loading. Please reload this page.