Allow - for stdout in path mapper (#147)
This commit is contained in:
@@ -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`.
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user