Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
ff1d3885
Commit
ff1d3885
authored
Aug 17, 2015
by
Marek Grabowski
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #12753 from eparis/rebase-pflag
Update spf13/pflag to fix StringSlice bug
parents
c0480e91
b3f0bc83
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
213 additions
and
16 deletions
+213
-16
Godeps.json
Godeps/Godeps.json
+2
-2
bool_test.go
Godeps/_workspace/src/github.com/spf13/pflag/bool_test.go
+1
-1
flag.go
Godeps/_workspace/src/github.com/spf13/pflag/flag.go
+9
-0
flag_test.go
Godeps/_workspace/src/github.com/spf13/pflag/flag_test.go
+28
-0
int_slice.go
Godeps/_workspace/src/github.com/spf13/pflag/int_slice.go
+16
-6
int_slice_test.go
...s/_workspace/src/github.com/spf13/pflag/int_slice_test.go
+78
-2
string_slice.go
Godeps/_workspace/src/github.com/spf13/pflag/string_slice.go
+19
-5
string_slice_test.go
...workspace/src/github.com/spf13/pflag/string_slice_test.go
+60
-0
No files found.
Godeps/Godeps.json
View file @
ff1d3885
...
@@ -488,8 +488,8 @@
...
@@ -488,8 +488,8 @@
},
},
{
{
"ImportPath"
:
"github.com/spf13/pflag"
,
"ImportPath"
:
"github.com/spf13/pflag"
,
"Comment"
:
"v0.0.1-
73-g534019b
"
,
"Comment"
:
"v0.0.1-
81-g4869ec2
"
,
"Rev"
:
"
534019bcaea096fc0f0641afa2aed1e80cbb0ccc
"
"Rev"
:
"
4869ec2ae0628354eaac5bf88fccf9a7265ae475
"
},
},
{
{
"ImportPath"
:
"github.com/stretchr/objx"
,
"ImportPath"
:
"github.com/stretchr/objx"
,
...
...
Godeps/_workspace/src/github.com/spf13/pflag/bool_test.go
View file @
ff1d3885
...
@@ -51,7 +51,7 @@ func (v *triStateValue) String() string {
...
@@ -51,7 +51,7 @@ func (v *triStateValue) String() string {
return
fmt
.
Sprintf
(
"%v"
,
bool
(
*
v
==
triStateTrue
))
return
fmt
.
Sprintf
(
"%v"
,
bool
(
*
v
==
triStateTrue
))
}
}
// The type of the flag as requred by the pflag.Value interface
// The type of the flag as requ
i
red by the pflag.Value interface
func
(
v
*
triStateValue
)
Type
()
string
{
func
(
v
*
triStateValue
)
Type
()
string
{
return
"version"
return
"version"
}
}
...
...
Godeps/_workspace/src/github.com/spf13/pflag/flag.go
View file @
ff1d3885
...
@@ -330,6 +330,15 @@ func (f *FlagSet) SetAnnotation(name, key string, values []string) error {
...
@@ -330,6 +330,15 @@ func (f *FlagSet) SetAnnotation(name, key string, values []string) error {
return
nil
return
nil
}
}
func
(
f
*
FlagSet
)
Changed
(
name
string
)
bool
{
flag
:=
f
.
Lookup
(
name
)
// If a flag doesn't exist, it wasn't changed....
if
flag
==
nil
{
return
false
}
return
flag
.
Changed
}
// Set sets the value of the named command-line flag.
// Set sets the value of the named command-line flag.
func
Set
(
name
,
value
string
)
error
{
func
Set
(
name
,
value
string
)
error
{
return
CommandLine
.
Set
(
name
,
value
)
return
CommandLine
.
Set
(
name
,
value
)
...
...
Godeps/_workspace/src/github.com/spf13/pflag/flag_test.go
View file @
ff1d3885
...
@@ -381,6 +381,34 @@ func TestFlagSetParse(t *testing.T) {
...
@@ -381,6 +381,34 @@ func TestFlagSetParse(t *testing.T) {
testParse
(
NewFlagSet
(
"test"
,
ContinueOnError
),
t
)
testParse
(
NewFlagSet
(
"test"
,
ContinueOnError
),
t
)
}
}
func
TestChangedHelper
(
t
*
testing
.
T
)
{
f
:=
NewFlagSet
(
"changedtest"
,
ContinueOnError
)
_
=
f
.
Bool
(
"changed"
,
false
,
"changed bool"
)
_
=
f
.
Bool
(
"settrue"
,
true
,
"true to true"
)
_
=
f
.
Bool
(
"setfalse"
,
false
,
"false to false"
)
_
=
f
.
Bool
(
"unchanged"
,
false
,
"unchanged bool"
)
args
:=
[]
string
{
"--changed"
,
"--settrue"
,
"--setfalse=false"
}
if
err
:=
f
.
Parse
(
args
);
err
!=
nil
{
t
.
Error
(
"f.Parse() = false after Parse"
)
}
if
!
f
.
Changed
(
"changed"
)
{
t
.
Errorf
(
"--changed wasn't changed!"
)
}
if
!
f
.
Changed
(
"settrue"
)
{
t
.
Errorf
(
"--settrue wasn't changed!"
)
}
if
!
f
.
Changed
(
"setfalse"
)
{
t
.
Errorf
(
"--setfalse wasn't changed!"
)
}
if
f
.
Changed
(
"unchanged"
)
{
t
.
Errorf
(
"--unchanged was changed!"
)
}
if
f
.
Changed
(
"invalid"
)
{
t
.
Errorf
(
"--invalid was changed!"
)
}
}
func
replaceSeparators
(
name
string
,
from
[]
string
,
to
string
)
string
{
func
replaceSeparators
(
name
string
,
from
[]
string
,
to
string
)
string
{
result
:=
name
result
:=
name
for
_
,
sep
:=
range
from
{
for
_
,
sep
:=
range
from
{
...
...
Godeps/_workspace/src/github.com/spf13/pflag/int_slice.go
View file @
ff1d3885
...
@@ -7,11 +7,16 @@ import (
...
@@ -7,11 +7,16 @@ import (
)
)
// -- intSlice Value
// -- intSlice Value
type
intSliceValue
[]
int
type
intSliceValue
struct
{
value
*
[]
int
changed
bool
}
func
newIntSliceValue
(
val
[]
int
,
p
*
[]
int
)
*
intSliceValue
{
func
newIntSliceValue
(
val
[]
int
,
p
*
[]
int
)
*
intSliceValue
{
*
p
=
val
isv
:=
new
(
intSliceValue
)
return
(
*
intSliceValue
)(
p
)
isv
.
value
=
p
*
isv
.
value
=
val
return
isv
}
}
func
(
s
*
intSliceValue
)
Set
(
val
string
)
error
{
func
(
s
*
intSliceValue
)
Set
(
val
string
)
error
{
...
@@ -25,7 +30,12 @@ func (s *intSliceValue) Set(val string) error {
...
@@ -25,7 +30,12 @@ func (s *intSliceValue) Set(val string) error {
}
}
}
}
*
s
=
append
(
*
s
,
out
...
)
if
!
s
.
changed
{
*
s
.
value
=
out
}
else
{
*
s
.
value
=
append
(
*
s
.
value
,
out
...
)
}
s
.
changed
=
true
return
nil
return
nil
}
}
...
@@ -34,8 +44,8 @@ func (s *intSliceValue) Type() string {
...
@@ -34,8 +44,8 @@ func (s *intSliceValue) Type() string {
}
}
func
(
s
*
intSliceValue
)
String
()
string
{
func
(
s
*
intSliceValue
)
String
()
string
{
out
:=
make
([]
string
,
len
(
*
s
))
out
:=
make
([]
string
,
len
(
*
s
.
value
))
for
i
,
d
:=
range
*
s
{
for
i
,
d
:=
range
*
s
.
value
{
out
[
i
]
=
fmt
.
Sprintf
(
"%d"
,
d
)
out
[
i
]
=
fmt
.
Sprintf
(
"%d"
,
d
)
}
}
return
"["
+
strings
.
Join
(
out
,
","
)
+
"]"
return
"["
+
strings
.
Join
(
out
,
","
)
+
"]"
...
...
Godeps/_workspace/src/github.com/spf13/pflag/int_slice_test.go
View file @
ff1d3885
...
@@ -17,6 +17,12 @@ func setUpISFlagSet(isp *[]int) *FlagSet {
...
@@ -17,6 +17,12 @@ func setUpISFlagSet(isp *[]int) *FlagSet {
return
f
return
f
}
}
func
setUpISFlagSetWithDefault
(
isp
*
[]
int
)
*
FlagSet
{
f
:=
NewFlagSet
(
"test"
,
ContinueOnError
)
f
.
IntSliceVar
(
isp
,
"is"
,
[]
int
{
0
,
1
},
"Command seperated list!"
)
return
f
}
func
TestEmptyIS
(
t
*
testing
.
T
)
{
func
TestEmptyIS
(
t
*
testing
.
T
)
{
var
is
[]
int
var
is
[]
int
f
:=
setUpISFlagSet
(
&
is
)
f
:=
setUpISFlagSet
(
&
is
)
...
@@ -27,7 +33,7 @@ func TestEmptyIS(t *testing.T) {
...
@@ -27,7 +33,7 @@ func TestEmptyIS(t *testing.T) {
getIS
,
err
:=
f
.
GetIntSlice
(
"is"
)
getIS
,
err
:=
f
.
GetIntSlice
(
"is"
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
"got an error from Get
String
Slice():"
,
err
)
t
.
Fatal
(
"got an error from Get
Int
Slice():"
,
err
)
}
}
if
len
(
getIS
)
!=
0
{
if
len
(
getIS
)
!=
0
{
t
.
Fatalf
(
"got is %v with len=%d but expected length=0"
,
getIS
,
len
(
getIS
))
t
.
Fatalf
(
"got is %v with len=%d but expected length=0"
,
getIS
,
len
(
getIS
))
...
@@ -65,6 +71,76 @@ func TestIS(t *testing.T) {
...
@@ -65,6 +71,76 @@ func TestIS(t *testing.T) {
}
}
}
}
func
TestISDefault
(
t
*
testing
.
T
)
{
var
is
[]
int
f
:=
setUpISFlagSetWithDefault
(
&
is
)
vals
:=
[]
string
{
"0"
,
"1"
}
err
:=
f
.
Parse
([]
string
{})
if
err
!=
nil
{
t
.
Fatal
(
"expected no error; got"
,
err
)
}
for
i
,
v
:=
range
is
{
d
,
err
:=
strconv
.
Atoi
(
vals
[
i
])
if
err
!=
nil
{
t
.
Fatalf
(
"got error: %v"
,
err
)
}
if
d
!=
v
{
t
.
Fatalf
(
"expected is[%d] to be %s but got: %s"
,
i
,
d
,
v
)
}
}
getIS
,
err
:=
f
.
GetIntSlice
(
"is"
)
if
err
!=
nil
{
t
.
Fatal
(
"got an error from GetIntSlice():"
,
err
)
}
for
i
,
v
:=
range
getIS
{
d
,
err
:=
strconv
.
Atoi
(
vals
[
i
])
if
err
!=
nil
{
t
.
Fatal
(
"got an error from GetIntSlice():"
,
err
)
}
if
d
!=
v
{
t
.
Fatalf
(
"expected is[%d] to be %s from GetIntSlice but got: %s"
,
i
,
d
,
v
)
}
}
}
func
TestISWithDefault
(
t
*
testing
.
T
)
{
var
is
[]
int
f
:=
setUpISFlagSetWithDefault
(
&
is
)
vals
:=
[]
string
{
"1"
,
"2"
}
arg
:=
fmt
.
Sprintf
(
"--is=%s"
,
strings
.
Join
(
vals
,
","
))
err
:=
f
.
Parse
([]
string
{
arg
})
if
err
!=
nil
{
t
.
Fatal
(
"expected no error; got"
,
err
)
}
for
i
,
v
:=
range
is
{
d
,
err
:=
strconv
.
Atoi
(
vals
[
i
])
if
err
!=
nil
{
t
.
Fatalf
(
"got error: %v"
,
err
)
}
if
d
!=
v
{
t
.
Fatalf
(
"expected is[%d] to be %s but got: %s"
,
i
,
d
,
v
)
}
}
getIS
,
err
:=
f
.
GetIntSlice
(
"is"
)
if
err
!=
nil
{
t
.
Fatal
(
"got an error from GetIntSlice():"
,
err
)
}
for
i
,
v
:=
range
getIS
{
d
,
err
:=
strconv
.
Atoi
(
vals
[
i
])
if
err
!=
nil
{
t
.
Fatalf
(
"got error: %v"
,
err
)
}
if
d
!=
v
{
t
.
Fatalf
(
"expected is[%d] to be %s from GetIntSlice but got: %s"
,
i
,
d
,
v
)
}
}
}
func
TestISCalledTwice
(
t
*
testing
.
T
)
{
func
TestISCalledTwice
(
t
*
testing
.
T
)
{
var
is
[]
int
var
is
[]
int
f
:=
setUpISFlagSet
(
&
is
)
f
:=
setUpISFlagSet
(
&
is
)
...
@@ -80,7 +156,7 @@ func TestISCalledTwice(t *testing.T) {
...
@@ -80,7 +156,7 @@ func TestISCalledTwice(t *testing.T) {
}
}
for
i
,
v
:=
range
is
{
for
i
,
v
:=
range
is
{
if
expected
[
i
]
!=
v
{
if
expected
[
i
]
!=
v
{
t
.
Fatalf
(
"expected
s
s[%d] to be %s but got: %s"
,
i
,
expected
[
i
],
v
)
t
.
Fatalf
(
"expected
i
s[%d] to be %s but got: %s"
,
i
,
expected
[
i
],
v
)
}
}
}
}
}
}
Godeps/_workspace/src/github.com/spf13/pflag/string_slice.go
View file @
ff1d3885
package
pflag
package
pflag
import
(
import
(
"fmt"
"strings"
"strings"
)
)
var
_
=
fmt
.
Fprint
// -- stringSlice Value
// -- stringSlice Value
type
stringSliceValue
[]
string
type
stringSliceValue
struct
{
value
*
[]
string
changed
bool
}
func
newStringSliceValue
(
val
[]
string
,
p
*
[]
string
)
*
stringSliceValue
{
func
newStringSliceValue
(
val
[]
string
,
p
*
[]
string
)
*
stringSliceValue
{
*
p
=
val
ssv
:=
new
(
stringSliceValue
)
return
(
*
stringSliceValue
)(
p
)
ssv
.
value
=
p
*
ssv
.
value
=
val
return
ssv
}
}
func
(
s
*
stringSliceValue
)
Set
(
val
string
)
error
{
func
(
s
*
stringSliceValue
)
Set
(
val
string
)
error
{
v
:=
strings
.
Split
(
val
,
","
)
v
:=
strings
.
Split
(
val
,
","
)
*
s
=
append
(
*
s
,
v
...
)
if
!
s
.
changed
{
*
s
.
value
=
v
}
else
{
*
s
.
value
=
append
(
*
s
.
value
,
v
...
)
}
s
.
changed
=
true
return
nil
return
nil
}
}
func
(
s
*
stringSliceValue
)
Type
()
string
{
func
(
s
*
stringSliceValue
)
Type
()
string
{
return
"stringSlice"
return
"stringSlice"
}
}
func
(
s
*
stringSliceValue
)
String
()
string
{
return
"["
+
strings
.
Join
(
*
s
,
","
)
+
"]"
}
func
(
s
*
stringSliceValue
)
String
()
string
{
return
"["
+
strings
.
Join
(
*
s
.
value
,
","
)
+
"]"
}
func
stringSliceConv
(
sval
string
)
(
interface
{},
error
)
{
func
stringSliceConv
(
sval
string
)
(
interface
{},
error
)
{
sval
=
strings
.
Trim
(
sval
,
"[]"
)
sval
=
strings
.
Trim
(
sval
,
"[]"
)
...
...
Godeps/_workspace/src/github.com/spf13/pflag/string_slice_test.go
View file @
ff1d3885
...
@@ -16,6 +16,12 @@ func setUpSSFlagSet(ssp *[]string) *FlagSet {
...
@@ -16,6 +16,12 @@ func setUpSSFlagSet(ssp *[]string) *FlagSet {
return
f
return
f
}
}
func
setUpSSFlagSetWithDefault
(
ssp
*
[]
string
)
*
FlagSet
{
f
:=
NewFlagSet
(
"test"
,
ContinueOnError
)
f
.
StringSliceVar
(
ssp
,
"ss"
,
[]
string
{
"default"
,
"values"
},
"Command seperated list!"
)
return
f
}
func
TestEmptySS
(
t
*
testing
.
T
)
{
func
TestEmptySS
(
t
*
testing
.
T
)
{
var
ss
[]
string
var
ss
[]
string
f
:=
setUpSSFlagSet
(
&
ss
)
f
:=
setUpSSFlagSet
(
&
ss
)
...
@@ -60,6 +66,60 @@ func TestSS(t *testing.T) {
...
@@ -60,6 +66,60 @@ func TestSS(t *testing.T) {
}
}
}
}
func
TestSSDefault
(
t
*
testing
.
T
)
{
var
ss
[]
string
f
:=
setUpSSFlagSetWithDefault
(
&
ss
)
vals
:=
[]
string
{
"default"
,
"values"
}
err
:=
f
.
Parse
([]
string
{})
if
err
!=
nil
{
t
.
Fatal
(
"expected no error; got"
,
err
)
}
for
i
,
v
:=
range
ss
{
if
vals
[
i
]
!=
v
{
t
.
Fatalf
(
"expected ss[%d] to be %s but got: %s"
,
i
,
vals
[
i
],
v
)
}
}
getSS
,
err
:=
f
.
GetStringSlice
(
"ss"
)
if
err
!=
nil
{
t
.
Fatal
(
"got an error from GetStringSlice():"
,
err
)
}
for
i
,
v
:=
range
getSS
{
if
vals
[
i
]
!=
v
{
t
.
Fatalf
(
"expected ss[%d] to be %s from GetStringSlice but got: %s"
,
i
,
vals
[
i
],
v
)
}
}
}
func
TestSSWithDefault
(
t
*
testing
.
T
)
{
var
ss
[]
string
f
:=
setUpSSFlagSetWithDefault
(
&
ss
)
vals
:=
[]
string
{
"one"
,
"two"
,
"4"
,
"3"
}
arg
:=
fmt
.
Sprintf
(
"--ss=%s"
,
strings
.
Join
(
vals
,
","
))
err
:=
f
.
Parse
([]
string
{
arg
})
if
err
!=
nil
{
t
.
Fatal
(
"expected no error; got"
,
err
)
}
for
i
,
v
:=
range
ss
{
if
vals
[
i
]
!=
v
{
t
.
Fatalf
(
"expected ss[%d] to be %s but got: %s"
,
i
,
vals
[
i
],
v
)
}
}
getSS
,
err
:=
f
.
GetStringSlice
(
"ss"
)
if
err
!=
nil
{
t
.
Fatal
(
"got an error from GetStringSlice():"
,
err
)
}
for
i
,
v
:=
range
getSS
{
if
vals
[
i
]
!=
v
{
t
.
Fatalf
(
"expected ss[%d] to be %s from GetStringSlice but got: %s"
,
i
,
vals
[
i
],
v
)
}
}
}
func
TestSSCalledTwice
(
t
*
testing
.
T
)
{
func
TestSSCalledTwice
(
t
*
testing
.
T
)
{
var
ss
[]
string
var
ss
[]
string
f
:=
setUpSSFlagSet
(
&
ss
)
f
:=
setUpSSFlagSet
(
&
ss
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment