Allow - for stdout in path mapper (#147)

This commit is contained in:
Andrew Haines
2021-03-02 05:26:10 +00:00
committed by GitHub
parent d48f4e59c3
commit 456575db97
3 changed files with 20 additions and 3 deletions
+2 -2
View File
@@ -385,8 +385,8 @@ function `NamedMapper(name, mapper)`.
| Name | Description
|-------------------|---------------------------------------------------
| `path` | A path. ~ expansion is applied.
| `existingfile` | An existing file. ~ expansion is applied. `-` is accepted for stdin.
| `path` | A path. ~ expansion is applied. `-` is accepted for stdout, and will be passed unaltered.
| `existingfile` | An existing file. ~ expansion is applied. `-` is accepted for stdin, and will be passed unaltered.
| `existingdir` | An existing directory. ~ expansion is applied.
| `counter` | Increment a numeric field. Useful for `-vvv`. Can accept `-s`, `--long` or `--long=N`.
+3 -1
View File
@@ -554,7 +554,9 @@ func pathMapper(r *Registry) MapperFunc {
if err != nil {
return err
}
path = ExpandPath(path)
if path != "-" {
path = ExpandPath(path)
}
target.SetString(path)
return nil
}
+15
View File
@@ -378,3 +378,18 @@ func TestFileMapper(t *testing.T) {
require.NoError(t, err)
require.Equal(t, os.Stdin, cli.File)
}
func TestPathMapper(t *testing.T) {
var cli struct {
Path string `arg:"" type:"path"`
}
p := mustNew(t, &cli)
_, err := p.Parse([]string{"/an/absolute/path"})
require.NoError(t, err)
require.Equal(t, "/an/absolute/path", cli.Path)
_, err = p.Parse([]string{"-"})
require.NoError(t, err)
require.Equal(t, "-", cli.Path)
}