Skip to content
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

Add gen-config command #1

Closed
themalkolm opened this issue Mar 6, 2017 · 1 comment
Closed

Add gen-config command #1

themalkolm opened this issue Mar 6, 2017 · 1 comment

Comments

@themalkolm
Copy link
Owner

It would be nice to automatically generate config structure for any command e.g.

var RootCmd = &cobra.Command{
	Use:          "foobar",
...
func init() {
	//
	// You need to define flags as usual.
	//
	RootCmd.PersistentFlags().String("foo", "", "Some foonees must be set")
	RootCmd.PersistentFlags().String("foo-bar", "", "Some barness must be set")
...
$ foobar gen-config -o ./config.go
...
$ cat ./config.o
type Config struct {
	Foo    string `mapstructure:"foo"`
	FooBar string `mapstructure:"foo-bar"`
}

So kind of self-updating code. The tricky part is to how to start this process. This could be done simply by having a dummy struct in the beginning to make sure code compiles.

@themalkolm
Copy link
Owner Author

What if we generate all flags from a config struct instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant