File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -756,3 +756,31 @@ func TestValuesThatLookLikeFlags(t *testing.T) {
756756 assert .NoError (t , err )
757757 assert .Equal (t , map [string ]string {"-foo" : "-bar" }, cli .Map )
758758}
759+
760+ type DecodeCLI struct {
761+ Foo DecodeFoo `env:"FOO"`
762+ }
763+
764+ type DecodeFoo struct {
765+ Bar string
766+ }
767+
768+ func (f DecodeFoo ) Decode (ctx * kong.DecodeContext ) error {
769+ ctx .Value .Target .Set (reflect .ValueOf (struct {
770+ Bar string
771+ }{"baz" }))
772+ return nil
773+ }
774+
775+ func TestDecode (t * testing.T ) {
776+ c := & DecodeCLI {}
777+ parser , err := kong .New (c )
778+ assert .NoError (t , err )
779+
780+ t .Setenv ("FOO" , "foo" )
781+
782+ _ , err = parser .Parse ([]string {})
783+ assert .NoError (t , err )
784+
785+ assert .Equal (t , c .Foo .Bar , "baz" )
786+ }
You can’t perform that action at this time.
0 commit comments