github.com/alecthomas/kong@v0.9.1-0.20240410131203-2ab5733f1179/defaults.go (about) 1 package kong 2 3 // ApplyDefaults if they are not already set. 4 func ApplyDefaults(target interface{}, options ...Option) error { 5 app, err := New(target, options...) 6 if err != nil { 7 return err 8 } 9 ctx, err := Trace(app, nil) 10 if err != nil { 11 return err 12 } 13 err = ctx.Resolve() 14 if err != nil { 15 return err 16 } 17 if err = ctx.ApplyDefaults(); err != nil { 18 return err 19 } 20 return ctx.Validate() 21 }