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

* Phase list command lists phases of current documentset/plan.
 airshipctl phase list
 airshipctl phase list --plan planName
 airshipctl phase list --plan planName -o table(default output)
 airshipctl phase list --plan planName -o yaml

Co-Authored-By: Niharika Bhavaraju <niha.twinkle@gmail.com>

Relates-To: #358

Change-Id: Iab3a6cdf5a25583ba3d01341da350841c9cc362d
This commit is contained in:
Niharika Bhavaraju 2021-01-05 11:08:11 -05:00
parent 9bf40366a5
commit 0cc7c9cafd
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.
Phases within a group are executed sequentially. Multiple phase groups
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}
planCmd := &cobra.Command{
Use: "list",
Short: "List phases",
Long: cmdLong[1:],
Use: "list PHASE_NAME",
Short: "List phases",
Long: cmdLong[1:],
Example: listExample,
RunE: func(cmd *cobra.Command, args []string) error {
p.Writer = cmd.OutOrStdout()
return p.RunE()
@ -62,4 +79,10 @@ func addListFlags(options *phase.ListCommand, cmd *cobra.Command) {
"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"
)
func TestNewPlanCommand(t *testing.T) {
func TestNewListCommand(t *testing.T) {
tests := []*testutil.CmdTest{
{
Name: "phase-plan-cmd-with-help",
Name: "phase-list-cmd-with-help",
CmdLine: "--help",
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
@ -18,6 +39,7 @@ airshipctl phase list [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

@ -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.
# 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.
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
# Guard against bootstrap or initinfra being missing, which could be the case for some configs