Merge "[#358] Introduce Phase List command to output phase list(cmd module)"

This commit is contained in:
Zuul 2021-03-30 01:02:39 +00:00 committed by Gerrit Code Review
commit 310bc282f5
6 changed files with 82 additions and 18 deletions

View File

@ -26,6 +26,22 @@ const (
List life-cycle phases which were defined in document model by group. List life-cycle phases which were defined in document model by group.
Phases within a group are executed sequentially. Multiple phase groups Phases within a group are executed sequentially. Multiple phase groups
are executed in parallel. are executed in parallel.
`
listExample = `
# List phases of phasePlan
airshipctl phase list --plan phasePlan
# To output the contents to table (default operation)
airshipctl phase list --plan phasePlan -o table
# To output the contents to yaml
airshipctl phase list --plan phasePlan -o yaml
# List all phases
airshipctl phase list
# List phases with clustername
airshipctl phase list --cluster-name clustername
` `
) )
@ -34,9 +50,10 @@ func NewListCommand(cfgFactory config.Factory) *cobra.Command {
p := &phase.ListCommand{Factory: cfgFactory} p := &phase.ListCommand{Factory: cfgFactory}
planCmd := &cobra.Command{ planCmd := &cobra.Command{
Use: "list", Use: "list PHASE_NAME",
Short: "List phases", Short: "List phases",
Long: cmdLong[1:], Long: cmdLong[1:],
Example: listExample,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
p.Writer = cmd.OutOrStdout() p.Writer = cmd.OutOrStdout()
return p.RunE() return p.RunE()
@ -62,4 +79,10 @@ func addListFlags(options *phase.ListCommand, cmd *cobra.Command) {
"plan", "plan",
"", "",
"Plan name of a plan") "Plan name of a plan")
flags.StringVarP(
&options.OutputFormat,
"output", "o", "table", "'table' "+
"and 'yaml' are available "+
"output formats")
} }

View File

@ -21,10 +21,10 @@ import (
"opendev.org/airship/airshipctl/testutil" "opendev.org/airship/airshipctl/testutil"
) )
func TestNewPlanCommand(t *testing.T) { func TestNewListCommand(t *testing.T) {
tests := []*testutil.CmdTest{ tests := []*testutil.CmdTest{
{ {
Name: "phase-plan-cmd-with-help", Name: "phase-list-cmd-with-help",
CmdLine: "--help", CmdLine: "--help",
Cmd: phase.NewListCommand(nil), Cmd: phase.NewListCommand(nil),
}, },

View File

@ -0,0 +1,30 @@
List life-cycle phases which were defined in document model by group.
Phases within a group are executed sequentially. Multiple phase groups
are executed in parallel.
Usage:
list PHASE_NAME [flags]
Examples:
# List phases of phasePlan
airshipctl phase list --plan phasePlan
# To output the contents to table (default operation)
airshipctl phase list --plan phasePlan -o table
# To output the contents to yaml
airshipctl phase list --plan phasePlan -o yaml
# List all phases
airshipctl phase list
# List phases with clustername
airshipctl phase list --cluster-name clustername
Flags:
-c, --cluster-name string filter documents by cluster name
-h, --help help for list
-o, --output string 'table' and 'yaml' are available output formats (default "table")
--plan string Plan name of a plan

View File

@ -1,11 +0,0 @@
List life-cycle phases which were defined in document model by group.
Phases within a group are executed sequentially. Multiple phase groups
are executed in parallel.
Usage:
list [flags]
Flags:
-c, --cluster-name string filter documents by cluster name
-h, --help help for list
--plan string Plan name of a plan

View File

@ -10,7 +10,28 @@ are executed in parallel.
``` ```
airshipctl phase list [flags] airshipctl phase list PHASE_NAME [flags]
```
### Examples
```
# List phases of phasePlan
airshipctl phase list --plan phasePlan
# To output the contents to table (default operation)
airshipctl phase list --plan phasePlan -o table
# To output the contents to yaml
airshipctl phase list --plan phasePlan -o yaml
# List all phases
airshipctl phase list
# List phases with clustername
airshipctl phase list --cluster-name clustername
``` ```
### Options ### Options
@ -18,6 +39,7 @@ airshipctl phase list [flags]
``` ```
-c, --cluster-name string filter documents by cluster name -c, --cluster-name string filter documents by cluster name
-h, --help help for list -h, --help help for list
-o, --output string 'table' and 'yaml' are available output formats (default "table")
--plan string Plan name of a plan --plan string Plan name of a plan
``` ```

View File

@ -119,7 +119,7 @@ for plan in $phase_plans; do
# removed since it was choking in certain cases and got to be more trouble than was worth. # removed since it was choking in certain cases and got to be more trouble than was worth.
# This should be removed once we have a phase map that is smarter. # This should be removed once we have a phase map that is smarter.
# In the meantime, as new phases are added, please add them here as well. # In the meantime, as new phases are added, please add them here as well.
phases=$(airshipctl --airshipconf ${AIRSHIPCONFIG} phase list --plan $plan -c $cluster | grep Phase | awk -F '/' '{print $2}' || true) phases=$(airshipctl --airshipconf ${AIRSHIPCONFIG} phase list --plan $plan -c $cluster | grep Phase | awk -F '/' '{print $2}' | awk '{print $1}' || true)
for phase in $phases; do for phase in $phases; do
# Guard against bootstrap or initinfra being missing, which could be the case for some configs # Guard against bootstrap or initinfra being missing, which could be the case for some configs