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
bb2fcd90
Unverified
Commit
bb2fcd90
authored
Nov 14, 2018
by
k8s-ci-robot
Committed by
GitHub
Nov 14, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #71040 from fabriziopandini/kubeadm-phases-local-flags
Kubeadm phases - add local flags
parents
12402742
1b9986b2
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
109 additions
and
71 deletions
+109
-71
init.go
cmd/kubeadm/app/cmd/init.go
+1
-1
addons.go
cmd/kubeadm/app/cmd/phases/addons.go
+13
-13
bootstraptoken.go
cmd/kubeadm/app/cmd/phases/bootstraptoken.go
+1
-1
certs.go
cmd/kubeadm/app/cmd/phases/certs.go
+7
-7
controlplane.go
cmd/kubeadm/app/cmd/phases/controlplane.go
+6
-6
etcd.go
cmd/kubeadm/app/cmd/phases/etcd.go
+6
-6
kubeconfig.go
cmd/kubeadm/app/cmd/phases/kubeconfig.go
+7
-7
kubelet.go
cmd/kubeadm/app/cmd/phases/kubelet.go
+1
-1
markcontrolplane.go
cmd/kubeadm/app/cmd/phases/markcontrolplane.go
+1
-1
preflight.go
cmd/kubeadm/app/cmd/phases/preflight.go
+1
-1
uploadconfig.go
cmd/kubeadm/app/cmd/phases/uploadconfig.go
+12
-12
phase.go
cmd/kubeadm/app/cmd/phases/workflow/phase.go
+12
-4
runner.go
cmd/kubeadm/app/cmd/phases/workflow/runner.go
+15
-7
runner_test.go
cmd/kubeadm/app/cmd/phases/workflow/runner_test.go
+26
-4
No files found.
cmd/kubeadm/app/cmd/init.go
View file @
bb2fcd90
...
@@ -155,7 +155,7 @@ func NewCmdInit(out io.Writer) *cobra.Command {
...
@@ -155,7 +155,7 @@ func NewCmdInit(out io.Writer) *cobra.Command {
// defines additional flag that are not used by the init command but that could be eventually used
// defines additional flag that are not used by the init command but that could be eventually used
// by the sub-commands automatically generated for phases
// by the sub-commands automatically generated for phases
initRunner
.
Set
PhaseSubcommands
AdditionalFlags
(
func
(
flags
*
flag
.
FlagSet
)
{
initRunner
.
SetAdditionalFlags
(
func
(
flags
*
flag
.
FlagSet
)
{
options
.
AddImageMetaFlags
(
flags
,
&
initOptions
.
externalcfg
.
ImageRepository
)
options
.
AddImageMetaFlags
(
flags
,
&
initOptions
.
externalcfg
.
ImageRepository
)
options
.
AddKubeConfigFlag
(
flags
,
&
initOptions
.
kubeconfigPath
)
options
.
AddKubeConfigFlag
(
flags
,
&
initOptions
.
kubeconfigPath
)
options
.
AddKubeConfigDirFlag
(
flags
,
&
initOptions
.
kubeconfigDir
)
options
.
AddKubeConfigDirFlag
(
flags
,
&
initOptions
.
kubeconfigDir
)
...
...
cmd/kubeadm/app/cmd/phases/addons.go
View file @
bb2fcd90
...
@@ -47,23 +47,23 @@ type addonData interface {
...
@@ -47,23 +47,23 @@ type addonData interface {
// NewAddonPhase returns the addon Cobra command
// NewAddonPhase returns the addon Cobra command
func
NewAddonPhase
()
workflow
.
Phase
{
func
NewAddonPhase
()
workflow
.
Phase
{
return
workflow
.
Phase
{
return
workflow
.
Phase
{
Name
:
"addon"
,
Name
:
"addon"
,
Short
:
"Installs required addons for passing Conformance tests"
,
Short
:
"Installs required addons for passing Conformance tests"
,
Cmd
Flags
:
getAddonPhaseFlags
(
"all"
),
Inherit
Flags
:
getAddonPhaseFlags
(
"all"
),
Phases
:
[]
workflow
.
Phase
{
Phases
:
[]
workflow
.
Phase
{
{
{
Name
:
"coredns"
,
Name
:
"coredns"
,
Short
:
"Installs the CoreDNS addon to a Kubernetes cluster"
,
Short
:
"Installs the CoreDNS addon to a Kubernetes cluster"
,
Long
:
coreDNSAddonLongDesc
,
Long
:
coreDNSAddonLongDesc
,
Cmd
Flags
:
getAddonPhaseFlags
(
"coredns"
),
Inherit
Flags
:
getAddonPhaseFlags
(
"coredns"
),
Run
:
runCoreDNSAddon
,
Run
:
runCoreDNSAddon
,
},
},
{
{
Name
:
"kube-proxy"
,
Name
:
"kube-proxy"
,
Short
:
"Installs the kube-proxy addon to a Kubernetes cluster"
,
Short
:
"Installs the kube-proxy addon to a Kubernetes cluster"
,
Long
:
kubeProxyAddonLongDesc
,
Long
:
kubeProxyAddonLongDesc
,
Cmd
Flags
:
getAddonPhaseFlags
(
"kube-proxy"
),
Inherit
Flags
:
getAddonPhaseFlags
(
"kube-proxy"
),
Run
:
runKubeProxyAddon
,
Run
:
runKubeProxyAddon
,
},
},
},
},
}
}
...
...
cmd/kubeadm/app/cmd/phases/bootstraptoken.go
View file @
bb2fcd90
...
@@ -64,7 +64,7 @@ func NewBootstrapTokenPhase() workflow.Phase {
...
@@ -64,7 +64,7 @@ func NewBootstrapTokenPhase() workflow.Phase {
Short
:
"Generates bootstrap tokens used to join a node to a cluster"
,
Short
:
"Generates bootstrap tokens used to join a node to a cluster"
,
Example
:
bootstrapTokenExamples
,
Example
:
bootstrapTokenExamples
,
Long
:
bootstrapTokenLongDesc
,
Long
:
bootstrapTokenLongDesc
,
Cmd
Flags
:
[]
string
{
Inherit
Flags
:
[]
string
{
options
.
CfgPath
,
options
.
CfgPath
,
options
.
KubeconfigDir
,
options
.
KubeconfigDir
,
options
.
SkipTokenPrint
,
options
.
SkipTokenPrint
,
...
...
cmd/kubeadm/app/cmd/phases/certs.go
View file @
bb2fcd90
...
@@ -60,11 +60,11 @@ type certsData interface {
...
@@ -60,11 +60,11 @@ type certsData interface {
// NewCertsPhase returns the phase for the certs
// NewCertsPhase returns the phase for the certs
func
NewCertsPhase
()
workflow
.
Phase
{
func
NewCertsPhase
()
workflow
.
Phase
{
return
workflow
.
Phase
{
return
workflow
.
Phase
{
Name
:
"certs"
,
Name
:
"certs"
,
Short
:
"Certificate generation"
,
Short
:
"Certificate generation"
,
Phases
:
newCertSubPhases
(),
Phases
:
newCertSubPhases
(),
Run
:
runCerts
,
Run
:
runCerts
,
Cmd
Flags
:
getCertPhaseFlags
(
"all"
),
Inherit
Flags
:
getCertPhaseFlags
(
"all"
),
}
}
}
}
...
@@ -107,8 +107,8 @@ func newCertSubPhase(certSpec *certsphase.KubeadmCert, run func(c workflow.RunDa
...
@@ -107,8 +107,8 @@ func newCertSubPhase(certSpec *certsphase.KubeadmCert, run func(c workflow.RunDa
certSpec
.
BaseName
,
certSpec
.
BaseName
,
getSANDescription
(
certSpec
),
getSANDescription
(
certSpec
),
),
),
Run
:
run
,
Run
:
run
,
Cmd
Flags
:
getCertPhaseFlags
(
certSpec
.
Name
),
Inherit
Flags
:
getCertPhaseFlags
(
certSpec
.
Name
),
}
}
return
phase
return
phase
}
}
...
...
cmd/kubeadm/app/cmd/phases/controlplane.go
View file @
bb2fcd90
...
@@ -77,18 +77,18 @@ func NewControlPlanePhase() workflow.Phase {
...
@@ -77,18 +77,18 @@ func NewControlPlanePhase() workflow.Phase {
newControlPlaneSubPhase
(
kubeadmconstants
.
KubeControllerManager
),
newControlPlaneSubPhase
(
kubeadmconstants
.
KubeControllerManager
),
newControlPlaneSubPhase
(
kubeadmconstants
.
KubeScheduler
),
newControlPlaneSubPhase
(
kubeadmconstants
.
KubeScheduler
),
},
},
Run
:
runControlPlanePhase
,
Run
:
runControlPlanePhase
,
Cmd
Flags
:
getControlPlanePhaseFlags
(
"all"
),
Inherit
Flags
:
getControlPlanePhaseFlags
(
"all"
),
}
}
return
phase
return
phase
}
}
func
newControlPlaneSubPhase
(
component
string
)
workflow
.
Phase
{
func
newControlPlaneSubPhase
(
component
string
)
workflow
.
Phase
{
phase
:=
workflow
.
Phase
{
phase
:=
workflow
.
Phase
{
Name
:
controlPlanePhaseProperties
[
component
]
.
name
,
Name
:
controlPlanePhaseProperties
[
component
]
.
name
,
Short
:
controlPlanePhaseProperties
[
component
]
.
short
,
Short
:
controlPlanePhaseProperties
[
component
]
.
short
,
Run
:
runControlPlaneSubPhase
(
component
),
Run
:
runControlPlaneSubPhase
(
component
),
Cmd
Flags
:
getControlPlanePhaseFlags
(
component
),
Inherit
Flags
:
getControlPlanePhaseFlags
(
component
),
}
}
return
phase
return
phase
}
}
...
...
cmd/kubeadm/app/cmd/phases/etcd.go
View file @
bb2fcd90
...
@@ -54,18 +54,18 @@ func NewEtcdPhase() workflow.Phase {
...
@@ -54,18 +54,18 @@ func NewEtcdPhase() workflow.Phase {
Phases
:
[]
workflow
.
Phase
{
Phases
:
[]
workflow
.
Phase
{
newEtcdLocalSubPhase
(),
newEtcdLocalSubPhase
(),
},
},
Cmd
Flags
:
getEtcdPhaseFlags
(),
Inherit
Flags
:
getEtcdPhaseFlags
(),
}
}
return
phase
return
phase
}
}
func
newEtcdLocalSubPhase
()
workflow
.
Phase
{
func
newEtcdLocalSubPhase
()
workflow
.
Phase
{
phase
:=
workflow
.
Phase
{
phase
:=
workflow
.
Phase
{
Name
:
"local"
,
Name
:
"local"
,
Short
:
"Generates the static Pod manifest file for a local, single-node local etcd instance."
,
Short
:
"Generates the static Pod manifest file for a local, single-node local etcd instance."
,
Example
:
etcdLocalExample
,
Example
:
etcdLocalExample
,
Run
:
runEtcdPhaseLocal
(),
Run
:
runEtcdPhaseLocal
(),
Cmd
Flags
:
getEtcdPhaseFlags
(),
Inherit
Flags
:
getEtcdPhaseFlags
(),
}
}
return
phase
return
phase
}
}
...
...
cmd/kubeadm/app/cmd/phases/kubeconfig.go
View file @
bb2fcd90
...
@@ -83,19 +83,19 @@ func NewKubeConfigPhase() workflow.Phase {
...
@@ -83,19 +83,19 @@ func NewKubeConfigPhase() workflow.Phase {
NewKubeConfigFilePhase
(
kubeadmconstants
.
ControllerManagerKubeConfigFileName
),
NewKubeConfigFilePhase
(
kubeadmconstants
.
ControllerManagerKubeConfigFileName
),
NewKubeConfigFilePhase
(
kubeadmconstants
.
SchedulerKubeConfigFileName
),
NewKubeConfigFilePhase
(
kubeadmconstants
.
SchedulerKubeConfigFileName
),
},
},
Run
:
runKubeConfig
,
Run
:
runKubeConfig
,
Cmd
Flags
:
getKubeConfigPhaseFlags
(
"all"
),
Inherit
Flags
:
getKubeConfigPhaseFlags
(
"all"
),
}
}
}
}
// NewKubeConfigFilePhase creates a kubeadm workflow phase that creates a kubeconfig file.
// NewKubeConfigFilePhase creates a kubeadm workflow phase that creates a kubeconfig file.
func
NewKubeConfigFilePhase
(
kubeConfigFileName
string
)
workflow
.
Phase
{
func
NewKubeConfigFilePhase
(
kubeConfigFileName
string
)
workflow
.
Phase
{
return
workflow
.
Phase
{
return
workflow
.
Phase
{
Name
:
kubeconfigFilePhaseProperties
[
kubeConfigFileName
]
.
name
,
Name
:
kubeconfigFilePhaseProperties
[
kubeConfigFileName
]
.
name
,
Short
:
kubeconfigFilePhaseProperties
[
kubeConfigFileName
]
.
short
,
Short
:
kubeconfigFilePhaseProperties
[
kubeConfigFileName
]
.
short
,
Long
:
fmt
.
Sprintf
(
kubeconfigFilePhaseProperties
[
kubeConfigFileName
]
.
long
,
kubeConfigFileName
),
Long
:
fmt
.
Sprintf
(
kubeconfigFilePhaseProperties
[
kubeConfigFileName
]
.
long
,
kubeConfigFileName
),
Run
:
runKubeConfigFile
(
kubeConfigFileName
),
Run
:
runKubeConfigFile
(
kubeConfigFileName
),
Cmd
Flags
:
getKubeConfigPhaseFlags
(
kubeConfigFileName
),
Inherit
Flags
:
getKubeConfigPhaseFlags
(
kubeConfigFileName
),
}
}
}
}
...
...
cmd/kubeadm/app/cmd/phases/kubelet.go
View file @
bb2fcd90
...
@@ -50,7 +50,7 @@ func NewKubeletStartPhase() workflow.Phase {
...
@@ -50,7 +50,7 @@ func NewKubeletStartPhase() workflow.Phase {
Long
:
"Writes a file with KubeletConfiguration and an environment file with node specific kubelet settings, and then (re)starts kubelet."
,
Long
:
"Writes a file with KubeletConfiguration and an environment file with node specific kubelet settings, and then (re)starts kubelet."
,
Example
:
kubeletStartPhaseExample
,
Example
:
kubeletStartPhaseExample
,
Run
:
runKubeletStart
,
Run
:
runKubeletStart
,
Cmd
Flags
:
[]
string
{
Inherit
Flags
:
[]
string
{
options
.
CfgPath
,
options
.
CfgPath
,
options
.
NodeCRISocket
,
options
.
NodeCRISocket
,
options
.
NodeName
,
options
.
NodeName
,
...
...
cmd/kubeadm/app/cmd/phases/markcontrolplane.go
View file @
bb2fcd90
...
@@ -48,7 +48,7 @@ func NewMarkControlPlanePhase() workflow.Phase {
...
@@ -48,7 +48,7 @@ func NewMarkControlPlanePhase() workflow.Phase {
Name
:
"mark-control-plane"
,
Name
:
"mark-control-plane"
,
Short
:
"Mark a node as a control-plane"
,
Short
:
"Mark a node as a control-plane"
,
Example
:
markControlPlaneExample
,
Example
:
markControlPlaneExample
,
Cmd
Flags
:
[]
string
{
Inherit
Flags
:
[]
string
{
options
.
NodeName
,
options
.
NodeName
,
},
},
Run
:
runMarkControlPlane
,
Run
:
runMarkControlPlane
,
...
...
cmd/kubeadm/app/cmd/phases/preflight.go
View file @
bb2fcd90
...
@@ -53,7 +53,7 @@ func NewPreflightMasterPhase() workflow.Phase {
...
@@ -53,7 +53,7 @@ func NewPreflightMasterPhase() workflow.Phase {
Long
:
"Run master pre-flight checks, functionally equivalent to what implemented by kubeadm init."
,
Long
:
"Run master pre-flight checks, functionally equivalent to what implemented by kubeadm init."
,
Example
:
masterPreflightExample
,
Example
:
masterPreflightExample
,
Run
:
runPreflightMaster
,
Run
:
runPreflightMaster
,
Cmd
Flags
:
[]
string
{
Inherit
Flags
:
[]
string
{
options
.
CfgPath
,
options
.
CfgPath
,
options
.
IgnorePreflightErrors
,
options
.
IgnorePreflightErrors
,
},
},
...
...
cmd/kubeadm/app/cmd/phases/uploadconfig.go
View file @
bb2fcd90
...
@@ -72,20 +72,20 @@ func NewUploadConfigPhase() workflow.Phase {
...
@@ -72,20 +72,20 @@ func NewUploadConfigPhase() workflow.Phase {
Long
:
cmdutil
.
MacroCommandLongDescription
,
Long
:
cmdutil
.
MacroCommandLongDescription
,
Phases
:
[]
workflow
.
Phase
{
Phases
:
[]
workflow
.
Phase
{
{
{
Name
:
"kubeadm"
,
Name
:
"kubeadm"
,
Short
:
"Uploads the kubeadm ClusterConfiguration to a ConfigMap"
,
Short
:
"Uploads the kubeadm ClusterConfiguration to a ConfigMap"
,
Long
:
uploadKubeadmConfigLongDesc
,
Long
:
uploadKubeadmConfigLongDesc
,
Example
:
uploadKubeadmConfigExample
,
Example
:
uploadKubeadmConfigExample
,
Run
:
runUploadKubeadmConfig
,
Run
:
runUploadKubeadmConfig
,
Cmd
Flags
:
getUploadConfigPhaseFlags
(),
Inherit
Flags
:
getUploadConfigPhaseFlags
(),
},
},
{
{
Name
:
"kubelet"
,
Name
:
"kubelet"
,
Short
:
"Uploads the kubelet component config to a ConfigMap"
,
Short
:
"Uploads the kubelet component config to a ConfigMap"
,
Long
:
uploadKubeletConfigLongDesc
,
Long
:
uploadKubeletConfigLongDesc
,
Example
:
uploadKubeletConfigExample
,
Example
:
uploadKubeletConfigExample
,
Run
:
runUploadKubeletConfig
,
Run
:
runUploadKubeletConfig
,
Cmd
Flags
:
getUploadConfigPhaseFlags
(),
Inherit
Flags
:
getUploadConfigPhaseFlags
(),
},
},
},
},
}
}
...
...
cmd/kubeadm/app/cmd/phases/workflow/phase.go
View file @
bb2fcd90
...
@@ -16,6 +16,8 @@ limitations under the License.
...
@@ -16,6 +16,8 @@ limitations under the License.
package
workflow
package
workflow
import
"github.com/spf13/pflag"
// Phase provides an implementation of a workflow phase that allows
// Phase provides an implementation of a workflow phase that allows
// creation of new phases by simply instantiating a variable of this type.
// creation of new phases by simply instantiating a variable of this type.
type
Phase
struct
{
type
Phase
struct
{
...
@@ -53,11 +55,17 @@ type Phase struct {
...
@@ -53,11 +55,17 @@ type Phase struct {
// If this function return nil, the phase action is always executed.
// If this function return nil, the phase action is always executed.
RunIf
func
(
data
RunData
)
(
bool
,
error
)
RunIf
func
(
data
RunData
)
(
bool
,
error
)
//
CmdFlags defines the list of flags that should be assigned to the cobra command generated
//
InheritFlags defines the list of flags that the cobra command generated for this phase should Inherit
// f
or this phase; flags are inherited from the parent command or defined as additional flags
// f
rom local flags defined in the parent command / or additional flags defined in the phase runner.
//
in the phase runner.
If the values is not set or empty, no flags will be assigned to the command
// If the values is not set or empty, no flags will be assigned to the command
// Nb. global flags are automatically inherited by nested cobra command
// Nb. global flags are automatically inherited by nested cobra command
CmdFlags
[]
string
InheritFlags
[]
string
// LocalFlags defines the list of flags that should be assigned to the cobra command generated
// for this phase.
// Nb. if two or phases have the same local flags, please consider using local flags in the parent command
// or additional flags defined in the phase runner.
LocalFlags
*
pflag
.
FlagSet
}
}
// AppendPhase adds the given phase to the nested, ordered sequence of phases.
// AppendPhase adds the given phase to the nested, ordered sequence of phases.
...
...
cmd/kubeadm/app/cmd/phases/workflow/runner.go
View file @
bb2fcd90
...
@@ -60,8 +60,8 @@ type Runner struct {
...
@@ -60,8 +60,8 @@ type Runner struct {
// more than one time)
// more than one time)
runData
RunData
runData
RunData
// cmdAdditionalFlags holds additional flags that could be added to the subcommands generated
// cmdAdditionalFlags holds additional
, shared
flags that could be added to the subcommands generated
// for
each phase. Flags could be inherited from the parent command too
// for
phases. Flags could be inherited from the parent command too or added directly to each phase
cmdAdditionalFlags
*
pflag
.
FlagSet
cmdAdditionalFlags
*
pflag
.
FlagSet
// phaseRunners is part of the internal state of the runner and provides
// phaseRunners is part of the internal state of the runner and provides
...
@@ -269,10 +269,11 @@ func (e *Runner) Help(cmdUse string) string {
...
@@ -269,10 +269,11 @@ func (e *Runner) Help(cmdUse string) string {
return
line
return
line
}
}
// Set
PhaseSubcommands
AdditionalFlags allows to define flags to be added
// SetAdditionalFlags allows to define flags to be added
// to the subcommands generated for each phase (but not existing in the parent command).
// to the subcommands generated for each phase (but not existing in the parent command).
// Please note that this command needs to be done before BindToCommand.
// Please note that this command needs to be done before BindToCommand.
func
(
e
*
Runner
)
SetPhaseSubcommandsAdditionalFlags
(
fn
func
(
*
pflag
.
FlagSet
))
{
// Nb. if a flag is used only by one phase, please consider using phase LocalFlags.
func
(
e
*
Runner
)
SetAdditionalFlags
(
fn
func
(
*
pflag
.
FlagSet
))
{
// creates a new NewFlagSet
// creates a new NewFlagSet
e
.
cmdAdditionalFlags
=
pflag
.
NewFlagSet
(
"phaseAdditionalFlags"
,
pflag
.
ContinueOnError
)
e
.
cmdAdditionalFlags
=
pflag
.
NewFlagSet
(
"phaseAdditionalFlags"
,
pflag
.
ContinueOnError
)
// invokes the function that sets additional flags
// invokes the function that sets additional flags
...
@@ -325,11 +326,18 @@ func (e *Runner) BindToCommand(cmd *cobra.Command) {
...
@@ -325,11 +326,18 @@ func (e *Runner) BindToCommand(cmd *cobra.Command) {
// makes the new command inherits local flags from the parent command
// makes the new command inherits local flags from the parent command
// Nb. global flags will be inherited automatically
// Nb. global flags will be inherited automatically
inheritsFlags
(
cmd
.
Flags
(),
phaseCmd
.
Flags
(),
p
.
Cmd
Flags
)
inheritsFlags
(
cmd
.
Flags
(),
phaseCmd
.
Flags
(),
p
.
Inherit
Flags
)
//
If defined, additional flags for phases should be added as well
//
makes the new command inherits additional flags for phases
if
e
.
cmdAdditionalFlags
!=
nil
{
if
e
.
cmdAdditionalFlags
!=
nil
{
inheritsFlags
(
e
.
cmdAdditionalFlags
,
phaseCmd
.
Flags
(),
p
.
CmdFlags
)
inheritsFlags
(
e
.
cmdAdditionalFlags
,
phaseCmd
.
Flags
(),
p
.
InheritFlags
)
}
// If defined, added phase local flags
if
p
.
LocalFlags
!=
nil
{
p
.
LocalFlags
.
VisitAll
(
func
(
f
*
pflag
.
Flag
)
{
phaseCmd
.
Flags
()
.
AddFlag
(
f
)
})
}
}
// adds the command to parent
// adds the command to parent
...
...
cmd/kubeadm/app/cmd/phases/workflow/runner_test.go
View file @
bb2fcd90
...
@@ -284,14 +284,25 @@ func TestHelp(t *testing.T) {
...
@@ -284,14 +284,25 @@ func TestHelp(t *testing.T) {
func
phaseBuilder4
(
name
string
,
cmdFlags
[]
string
,
phases
...
Phase
)
Phase
{
func
phaseBuilder4
(
name
string
,
cmdFlags
[]
string
,
phases
...
Phase
)
Phase
{
return
Phase
{
return
Phase
{
Name
:
name
,
Name
:
name
,
Phases
:
phases
,
Phases
:
phases
,
CmdFlags
:
cmdFlags
,
InheritFlags
:
cmdFlags
,
}
}
func
phaseBuilder5
(
name
string
,
flags
*
pflag
.
FlagSet
)
Phase
{
return
Phase
{
Name
:
name
,
LocalFlags
:
flags
,
}
}
}
}
func
TestBindToCommand
(
t
*
testing
.
T
)
{
func
TestBindToCommand
(
t
*
testing
.
T
)
{
var
dummy
string
localFlags
:=
pflag
.
NewFlagSet
(
"dummy"
,
pflag
.
ContinueOnError
)
localFlags
.
StringVarP
(
&
dummy
,
"flag4"
,
"d"
,
"d"
,
"d"
)
var
usecases
=
[]
struct
{
var
usecases
=
[]
struct
{
name
string
name
string
runner
Runner
runner
Runner
...
@@ -340,12 +351,22 @@ func TestBindToCommand(t *testing.T) {
...
@@ -340,12 +351,22 @@ func TestBindToCommand(t *testing.T) {
},
},
},
},
{
{
name
:
"it should be possible to apply custom flags to single phases"
,
runner
:
Runner
{
Phases
:
[]
Phase
{
phaseBuilder5
(
"foo"
,
localFlags
)},
},
expectedCmdAndFlags
:
map
[
string
][]
string
{
"phase foo"
:
{
"flag4"
},
},
},
{
name
:
"all the above applies to nested phases too"
,
name
:
"all the above applies to nested phases too"
,
runner
:
Runner
{
runner
:
Runner
{
Phases
:
[]
Phase
{
Phases
:
[]
Phase
{
phaseBuilder4
(
"foo"
,
[]
string
{
"flag3"
},
phaseBuilder4
(
"foo"
,
[]
string
{
"flag3"
},
phaseBuilder4
(
"bar"
,
[]
string
{
"flag1"
,
"flag2"
,
"flag3"
}),
phaseBuilder4
(
"bar"
,
[]
string
{
"flag1"
,
"flag2"
,
"flag3"
}),
phaseBuilder4
(
"baz"
,
[]
string
{
"flag1"
}),
//test if additional flags are filtered too
phaseBuilder4
(
"baz"
,
[]
string
{
"flag1"
}),
//test if additional flags are filtered too
phaseBuilder5
(
"qux"
,
localFlags
),
),
),
},
},
},
},
...
@@ -357,6 +378,7 @@ func TestBindToCommand(t *testing.T) {
...
@@ -357,6 +378,7 @@ func TestBindToCommand(t *testing.T) {
"phase foo"
:
{
"flag3"
},
"phase foo"
:
{
"flag3"
},
"phase foo bar"
:
{
"flag1"
,
"flag2"
,
"flag3"
},
"phase foo bar"
:
{
"flag1"
,
"flag2"
,
"flag3"
},
"phase foo baz"
:
{
"flag1"
},
"phase foo baz"
:
{
"flag1"
},
"phase foo qux"
:
{
"flag4"
},
},
},
},
},
}
}
...
@@ -372,7 +394,7 @@ func TestBindToCommand(t *testing.T) {
...
@@ -372,7 +394,7 @@ func TestBindToCommand(t *testing.T) {
cmd
.
Flags
()
.
StringVarP
(
&
dummy2
,
"flag2"
,
"b"
,
"b"
,
"b"
)
cmd
.
Flags
()
.
StringVarP
(
&
dummy2
,
"flag2"
,
"b"
,
"b"
,
"b"
)
if
rt
.
setAdditionalFlags
!=
nil
{
if
rt
.
setAdditionalFlags
!=
nil
{
rt
.
runner
.
Set
PhaseSubcommands
AdditionalFlags
(
rt
.
setAdditionalFlags
)
rt
.
runner
.
SetAdditionalFlags
(
rt
.
setAdditionalFlags
)
}
}
rt
.
runner
.
BindToCommand
(
cmd
)
rt
.
runner
.
BindToCommand
(
cmd
)
...
...
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