Documentation ¶
Overview ¶
Package urfave This is an interceptor dedicated to push flags from https://github.com/urfave/cli to the final schema given by gautocloud. if flags is not a zero value it will override value from schema given by gautocloud.
Example ¶
cliInterceptor := NewCli() type MyConfig struct { Foo string Bar bool Orig string } // Initialize a fake cloud env only for example, normally you should do this in init() function os.Clearenv() os.Setenv("DYNO", "true") // Here we set a value for Orig field from MyConfig schema os.Setenv("CONFIG_ORIG", "<injected by gautocloud>") gautocloud.RegisterConnector(generic.NewConfigGenericConnector(MyConfig{}, cliInterceptor)) gautocloud.ReloadConnectors() ////// // This is our urfave cli command action action := func(c *cli.Context) error { config := MyConfig{} // We pass context to interceptor, this is mandatory cliInterceptor.SetContext(c) // We are asking to retrieve a config schema through injection err := gautocloud.Inject(&config) if err != nil { panic(err) } // We can see that we have our config altered by flags found by urfave/cli fmt.Println(fmt.Sprintf("%#v", config)) return nil } // Here we simply create a fake urfave/cli app app := cli.NewApp() app.Flags = []cli.Flag{ cli.StringFlag{ Name: "foo, f", Value: "Foo", Usage: "foo", }, } app.Commands = []cli.Command{ { Name: "doo", Aliases: []string{"do"}, Category: "motion", Usage: "do the doo", UsageText: "doo - does the dooing", Description: "no really, there is a lot of dooing to be done", ArgsUsage: "[arrgh]", Flags: []cli.Flag{ cli.BoolFlag{Name: "bar, b"}, }, Action: action, }, } app.Run([]string{"app", "--foo=bar", "doo", "--bar"})
Output: urfave_test.MyConfig{Foo:"bar", Bar:true, Orig:"<injected by gautocloud>"}
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CliInterceptor ¶
type CliInterceptor struct {
// contains filtered or unexported fields
}
func NewCli ¶
func NewCli() *CliInterceptor
func (CliInterceptor) Intercept ¶
func (i CliInterceptor) Intercept(current, found interface{}) (interface{}, error)
func (*CliInterceptor) SetContext ¶
func (i *CliInterceptor) SetContext(context *cli.Context)
Click to show internal directories.
Click to hide internal directories.