main: "--" should also block "-o" parsing
Includes test cases.
This commit is contained in:
parent
edb3e19cb5
commit
e135a72bda
@ -162,6 +162,7 @@ v1.3 (in progress)
|
||||
* Use stable 64-bit inode numbers in reverse mode
|
||||
* This may cause problems for very old 32-bit applications
|
||||
that were compiled without Large File Support.
|
||||
* Passing "--" now also block "-o" parsing
|
||||
|
||||
v1.2.1, 2017-02-26
|
||||
* Add an integrated speed test, `gocryptfs -speed`
|
||||
|
10
cli_args.go
10
cli_args.go
@ -36,11 +36,19 @@ var flagSet *flag.FlagSet
|
||||
|
||||
// prefixOArgs transform options passed via "-o foo,bar" into regular options
|
||||
// like "-foo -bar" and prefixes them to the command line.
|
||||
// Testcases in TestPrefixOArgs().
|
||||
func prefixOArgs(osArgs []string) []string {
|
||||
// Need at least 3, example: gocryptfs -o foo,bar
|
||||
// Need at least 3, example: gocryptfs -o foo,bar
|
||||
// ^ 0 ^ 1 ^ 2
|
||||
if len(osArgs) < 3 {
|
||||
return osArgs
|
||||
}
|
||||
// Passing "--" disables "-o" parsing. Ignore element 0 (program name).
|
||||
for _, v := range osArgs[1:] {
|
||||
if v == "--" {
|
||||
return osArgs
|
||||
}
|
||||
}
|
||||
// Find and extract "-o foo,bar"
|
||||
var otherArgs, oOpts []string
|
||||
for i := 1; i < len(osArgs); i++ {
|
||||
|
@ -12,6 +12,7 @@ type testcase struct {
|
||||
o []string
|
||||
}
|
||||
|
||||
// TestPrefixOArgs checks that the "-o x,y,z" parsing works correctly.
|
||||
func TestPrefixOArgs(t *testing.T) {
|
||||
testcases := []testcase{
|
||||
{
|
||||
@ -51,6 +52,15 @@ func TestPrefixOArgs(t *testing.T) {
|
||||
i: []string{"gocryptfs", "-o", "rw", "--config", "fff", "ccc", "mmm"},
|
||||
o: []string{"gocryptfs", "-rw", "--config", "fff", "ccc", "mmm"},
|
||||
},
|
||||
// "--" should also block "-o" parsing.
|
||||
{
|
||||
i: []string{"gocryptfs", "foo", "bar", "--", "-o", "a"},
|
||||
o: []string{"gocryptfs", "foo", "bar", "--", "-o", "a"},
|
||||
},
|
||||
{
|
||||
i: []string{"gocryptfs", "--", "-o", "a"},
|
||||
o: []string{"gocryptfs", "--", "-o", "a"},
|
||||
},
|
||||
}
|
||||
for _, tc := range testcases {
|
||||
o := prefixOArgs(tc.i)
|
||||
|
Loading…
Reference in New Issue
Block a user