File: defaults.go

package info (click to toggle)
golang-github-alecthomas-kong 0.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 620 kB
  • sloc: makefile: 2
file content (21 lines) | stat: -rw-r--r-- 397 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package kong

// ApplyDefaults if they are not already set.
func ApplyDefaults(target interface{}, options ...Option) error {
	app, err := New(target, options...)
	if err != nil {
		return err
	}
	ctx, err := Trace(app, nil)
	if err != nil {
		return err
	}
	err = ctx.Resolve()
	if err != nil {
		return err
	}
	if err = ctx.ApplyDefaults(); err != nil {
		return err
	}
	return ctx.Validate()
}