@@ -487,6 +487,49 @@ func TestFileContentMapper(t *testing.T) {
487
487
assert .Contains (t , err .Error (), "is a directory" )
488
488
}
489
489
490
+ func TestPathMapperUsingStringPointer (t * testing.T ) {
491
+ type CLI struct {
492
+ Path * string `type:"path"`
493
+ }
494
+ var cli CLI
495
+
496
+ t .Run ("With value" , func (t * testing.T ) {
497
+ p := mustNew (t , & cli )
498
+ _ , err := p .Parse ([]string {"--path" , "/foo/bar" })
499
+ assert .NoError (t , err )
500
+ assert .NotZero (t , cli .Path )
501
+ assert .Equal (t , "/foo/bar" , * cli .Path )
502
+ })
503
+
504
+ t .Run ("Zero value" , func (t * testing.T ) {
505
+ p := mustNew (t , & cli )
506
+ _ , err := p .Parse ([]string {"--path" , "" })
507
+ assert .NoError (t , err )
508
+ assert .NotZero (t , cli .Path )
509
+ wd , err := os .Getwd ()
510
+ assert .NoError (t , err )
511
+ assert .Equal (t , wd , * cli .Path )
512
+ })
513
+
514
+ t .Run ("Without value" , func (t * testing.T ) {
515
+ p := mustNew (t , & cli )
516
+ _ , err := p .Parse ([]string {"--" })
517
+ assert .NoError (t , err )
518
+ assert .Equal (t , nil , cli .Path )
519
+ })
520
+
521
+ t .Run ("Non-string pointer" , func (t * testing.T ) {
522
+ type CLI struct {
523
+ Path * any `type:"path"`
524
+ }
525
+ var cli CLI
526
+ p := mustNew (t , & cli )
527
+ _ , err := p .Parse ([]string {"--path" , "" })
528
+ assert .Error (t , err )
529
+ assert .Contains (t , err .Error (), `"path" type must be applied to a string` )
530
+ })
531
+ }
532
+
490
533
//nolint:dupl
491
534
func TestExistingFileMapper (t * testing.T ) {
492
535
type CLI struct {
0 commit comments