-
-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
treat \ as escape only before a separator
- Loading branch information
1 parent
5538b7f
commit 29685e7
Showing
5 changed files
with
86 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
package kong_test | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
package kong_test | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestWindowsPathMapper(t *testing.T) { | ||
var cli struct { | ||
Path string `short:"p" type:"path"` | ||
Files []string `short:"f" type:"path"` | ||
} | ||
wd, err := os.Getwd() | ||
require.NoError(t, err, "Getwd failed") | ||
p := mustNew(t, &cli) | ||
|
||
_, err = p.Parse([]string{`-p`, `c:\an\absolute\path`, `-f`, `c:\second\absolute\path\`, `-f`, `relative\path\file`}) | ||
require.NoError(t, err) | ||
require.Equal(t, `c:\an\absolute\path`, cli.Path) | ||
require.Equal(t, []string{`c:\second\absolute\path\`, wd + `\relative\path\file`}, cli.Files) | ||
} | ||
|
||
func TestWindowsFileMapper(t *testing.T) { | ||
type CLI struct { | ||
File *os.File `arg:""` | ||
} | ||
var cli CLI | ||
p := mustNew(t, &cli) | ||
_, err := p.Parse([]string{"testdata\\file.txt"}) | ||
require.NoError(t, err) | ||
require.NotNil(t, cli.File) | ||
_ = cli.File.Close() | ||
_, err = p.Parse([]string{"testdata\\missing.txt"}) | ||
require.Error(t, err) | ||
require.Contains(t, err.Error(), "missing.txt: The system cannot find the file specified.") | ||
_, err = p.Parse([]string{"-"}) | ||
require.NoError(t, err) | ||
require.Equal(t, os.Stdin, cli.File) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters