| 645 | } |
| 646 | |
| 647 | func TestExistingFileMapperDefaultMissingCmds(t *testing.T) { |
| 648 | type CLI struct { |
| 649 | CmdA struct { |
| 650 | FileA string `type:"existingfile" default:"testdata/aaa-missing.txt"` |
| 651 | FileB string `type:"existingfile" default:"testdata/bbb-missing.txt"` |
| 652 | } `cmd:""` |
| 653 | CmdC struct { |
| 654 | FileC string `type:"existingfile" default:"testdata/ccc-missing.txt"` |
| 655 | } `cmd:""` |
| 656 | } |
| 657 | var cli CLI |
| 658 | file := filepath.Join("testdata", "file.txt") |
| 659 | p := mustNew(t, &cli) |
| 660 | _, err := p.Parse([]string{"cmd-a", "--file-a", file, "--file-b", file}) |
| 661 | assert.NoError(t, err) |
| 662 | assert.NotZero(t, cli.CmdA.FileA) |
| 663 | assert.Contains(t, cli.CmdA.FileA, file) |
| 664 | assert.NotZero(t, cli.CmdA.FileB) |
| 665 | assert.Contains(t, cli.CmdA.FileB, file) |
| 666 | p = mustNew(t, &cli) |
| 667 | _, err = p.Parse([]string{"cmd-a", "--file-a", file}) |
| 668 | assert.Error(t, err) |
| 669 | assert.Contains(t, err.Error(), "bbb-missing.txt:") |
| 670 | assert.IsError(t, err, os.ErrNotExist) |
| 671 | } |
| 672 | |
| 673 | //nolint:dupl |
| 674 | func TestExistingDirMapper(t *testing.T) { |