Skip to content
Myr

Adding "OnInitialize()" method instead of directly setting a property. Now can have multiple initializers.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by spf13 · committed by spf13 · parent 7cebca3 · Browse files · 2 files+8 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+8 added−5 removed

  • other:+8 added−5 removed

2 files+8 added−5 removed

modified:cobra.go+5 added-4 removed
23 unmodified lines
24 "strings"25 "text/template"26)2728// Called after flags are parsed immediately before executing any Command29var InitializeConfig func()28var initializers []func()2931func init() {32 InitializeConfig = func() {}30func OnInitialize(y ...func()) {31 for _, x := range y {32 initializers = append(initializers, x)33 }34}3536func Gt(a interface{}, b interface{}) bool {37 var left, right int64
57 unmodified lines
modified:command.go+3 added-1 removed
356 unmodified lines
357 }358}359360func (c *Command) preRun() {361 InitializeConfig()361 for _, x := range initializers {362 x()363 }364}365366func (c *Command) errorMsgFromParse() string {367 s := c.flagErrorBuf.String()
370 unmodified lines