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
f98cd70c
Commit
f98cd70c
authored
Mar 13, 2015
by
Brendan Burns
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update the cobra and pflag libraries with upstream fixes.
parent
232796db
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
174 additions
and
90 deletions
+174
-90
Godeps.json
Godeps/Godeps.json
+2
-2
cobra_test.go
Godeps/_workspace/src/github.com/spf13/cobra/cobra_test.go
+45
-3
command.go
Godeps/_workspace/src/github.com/spf13/cobra/command.go
+121
-83
bool_test.go
Godeps/_workspace/src/github.com/spf13/pflag/bool_test.go
+1
-1
example_test.go
Godeps/_workspace/src/github.com/spf13/pflag/example_test.go
+1
-1
flag.go
Godeps/_workspace/src/github.com/spf13/pflag/flag.go
+4
-0
No files found.
Godeps/Godeps.json
View file @
f98cd70c
...
...
@@ -357,11 +357,11 @@
},
{
"ImportPath"
:
"github.com/spf13/cobra"
,
"Rev"
:
"
f8e1ec56bdd7494d309c69681267859a6bfb7549
"
"Rev"
:
"
9e7273d5469dd5e04a35fd8823ba510117448c0b
"
},
{
"ImportPath"
:
"github.com/spf13/pflag"
,
"Rev"
:
"
370c3171201099fa6b466db45c8a032cbce33d8d
"
"Rev"
:
"
11b7cf8387a31f278486eaad758162830eca8c73
"
},
{
"ImportPath"
:
"github.com/stretchr/objx"
,
...
...
Godeps/_workspace/src/github.com/spf13/cobra/cobra_test.go
View file @
f98cd70c
...
...
@@ -11,11 +11,14 @@ var _ = fmt.Println
var
tp
,
te
,
tt
,
t1
[]
string
var
flagb1
,
flagb2
,
flagb3
,
flagbr
bool
var
flags1
,
flags2
,
flags3
string
var
flags1
,
flags2
a
,
flags2b
,
flags3
string
var
flagi1
,
flagi2
,
flagi3
,
flagir
int
var
globalFlag1
bool
var
flagEcho
,
rootcalled
bool
const
strtwoParentHelp
=
"help message for parent flag strtwo"
const
strtwoChildHelp
=
"help message for child flag strtwo"
var
cmdPrint
=
&
Command
{
Use
:
"print [string to print]"
,
Short
:
"Print anything to the screen"
,
...
...
@@ -72,11 +75,12 @@ func flagInit() {
cmdRootNoRun
.
ResetFlags
()
cmdRootSameName
.
ResetFlags
()
cmdRootWithRun
.
ResetFlags
()
cmdRootNoRun
.
PersistentFlags
()
.
StringVarP
(
&
flags2a
,
"strtwo"
,
"t"
,
"two"
,
strtwoParentHelp
)
cmdEcho
.
Flags
()
.
IntVarP
(
&
flagi1
,
"intone"
,
"i"
,
123
,
"help message for flag intone"
)
cmdTimes
.
Flags
()
.
IntVarP
(
&
flagi2
,
"inttwo"
,
"j"
,
234
,
"help message for flag inttwo"
)
cmdPrint
.
Flags
()
.
IntVarP
(
&
flagi3
,
"intthree"
,
"i"
,
345
,
"help message for flag intthree"
)
cmdEcho
.
PersistentFlags
()
.
StringVarP
(
&
flags1
,
"strone"
,
"s"
,
"one"
,
"help message for flag strone"
)
cmdTimes
.
PersistentFlags
()
.
StringVarP
(
&
flags2
,
"strtwo"
,
"t"
,
"two"
,
"help message for flag strtwo"
)
cmdTimes
.
PersistentFlags
()
.
StringVarP
(
&
flags2
b
,
"strtwo"
,
"t"
,
"2"
,
strtwoChildHelp
)
cmdPrint
.
PersistentFlags
()
.
StringVarP
(
&
flags3
,
"strthree"
,
"s"
,
"three"
,
"help message for flag strthree"
)
cmdEcho
.
Flags
()
.
BoolVarP
(
&
flagb1
,
"boolone"
,
"b"
,
true
,
"help message for flag boolone"
)
cmdTimes
.
Flags
()
.
BoolVarP
(
&
flagb2
,
"booltwo"
,
"c"
,
false
,
"help message for flag booltwo"
)
...
...
@@ -377,10 +381,21 @@ func TestChildCommandFlags(t *testing.T) {
t
.
Errorf
(
"invalid flag should generate error"
)
}
if
!
strings
.
Contains
(
r
.
Output
,
"
intone=123
"
)
{
if
!
strings
.
Contains
(
r
.
Output
,
"
unknown shorthand flag
"
)
{
t
.
Errorf
(
"Wrong error message displayed,
\n
%s"
,
r
.
Output
)
}
// Testing with persistent flag overwritten by child
noRRSetupTest
(
"echo times --strtwo=child one two"
)
if
flags2b
!=
"child"
{
t
.
Errorf
(
"flag value should be child, %s given"
,
flags2b
)
}
if
flags2a
!=
"two"
{
t
.
Errorf
(
"unset flag should have default value, expecting two, given %s"
,
flags2a
)
}
// Testing flag with invalid input
r
=
noRRSetupTest
(
"echo -i10E"
)
...
...
@@ -437,6 +452,13 @@ func TestHelpCommand(t *testing.T) {
checkResultContains
(
t
,
r
,
cmdTimes
.
Long
)
}
func
TestChildCommandHelp
(
t
*
testing
.
T
)
{
c
:=
noRRSetupTest
(
"print --help"
)
checkResultContains
(
t
,
c
,
strtwoParentHelp
)
r
:=
noRRSetupTest
(
"echo times --help"
)
checkResultContains
(
t
,
r
,
strtwoChildHelp
)
}
func
TestRunnableRootCommand
(
t
*
testing
.
T
)
{
fullSetupTest
(
""
)
...
...
@@ -486,6 +508,26 @@ func TestRootHelp(t *testing.T) {
}
func
TestFlagAccess
(
t
*
testing
.
T
)
{
initialize
()
local
:=
cmdTimes
.
LocalFlags
()
inherited
:=
cmdTimes
.
InheritedFlags
()
for
_
,
f
:=
range
[]
string
{
"inttwo"
,
"strtwo"
,
"booltwo"
}
{
if
local
.
Lookup
(
f
)
==
nil
{
t
.
Errorf
(
"LocalFlags expected to contain %s, Got: nil"
,
f
)
}
}
if
inherited
.
Lookup
(
"strone"
)
==
nil
{
t
.
Errorf
(
"InheritedFlags expected to contain strone, Got: nil"
)
}
if
inherited
.
Lookup
(
"strtwo"
)
!=
nil
{
t
.
Errorf
(
"InheritedFlags shouldn not contain overwritten flag strtwo"
)
}
}
func
TestRootNoCommandHelp
(
t
*
testing
.
T
)
{
x
:=
rootOnlySetupTest
(
"--help"
)
...
...
Godeps/_workspace/src/github.com/spf13/cobra/command.go
View file @
f98cd70c
This diff is collapsed.
Click to expand it.
Godeps/_workspace/src/github.com/spf13/pflag/bool_test.go
View file @
f98cd70c
...
...
@@ -9,7 +9,7 @@ import (
"strconv"
"testing"
.
"github.com/
ogier
/pflag"
.
"github.com/
spf13
/pflag"
)
// This value can be a boolean ("true", "false") or "maybe"
...
...
Godeps/_workspace/src/github.com/spf13/pflag/example_test.go
View file @
f98cd70c
...
...
@@ -11,7 +11,7 @@ import (
"strings"
"time"
flag
"github.com/
ogier
/pflag"
flag
"github.com/
spf13
/pflag"
)
// Example 1: A single string flag called "species" with default value "gopher".
...
...
Godeps/_workspace/src/github.com/spf13/pflag/flag.go
View file @
f98cd70c
...
...
@@ -498,6 +498,7 @@ func (f *FlagSet) parseShortArg(s string, args []string) (a []string, err error)
if
len
(
args
)
==
0
{
return
}
return
}
if
alreadythere
{
if
bv
,
ok
:=
flag
.
Value
.
(
boolFlag
);
ok
&&
bv
.
IsBoolFlag
()
{
...
...
@@ -551,6 +552,9 @@ func (f *FlagSet) parseArgs(args []string) (err error) {
}
else
{
args
,
err
=
f
.
parseShortArg
(
s
,
args
)
}
if
err
!=
nil
{
return
}
}
return
}
...
...
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