From 0cc7c9cafdba47f6d26f81fa99d3c066c626cc85 Mon Sep 17 00:00:00 2001 From: Niharika Bhavaraju Date: Tue, 5 Jan 2021 11:08:11 -0500 Subject: [PATCH] [#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 Relates-To: #358 Change-Id: Iab3a6cdf5a25583ba3d01341da350841c9cc362d --- cmd/phase/list.go | 29 ++++++++++++++++-- cmd/phase/list_test.go | 4 +-- .../phase-list-cmd-with-help.golden | 30 +++++++++++++++++++ .../phase-plan-cmd-with-help.golden | 11 ------- docs/source/cli/airshipctl_phase_list.md | 24 ++++++++++++++- tools/document/validate_site_docs.sh | 2 +- 6 files changed, 82 insertions(+), 18 deletions(-) create mode 100644 cmd/phase/testdata/TestNewListCommandGoldenOutput/phase-list-cmd-with-help.golden delete mode 100644 cmd/phase/testdata/TestNewPlanCommandGoldenOutput/phase-plan-cmd-with-help.golden diff --git a/cmd/phase/list.go b/cmd/phase/list.go index bfa50dadd..8d3b581cf 100644 --- a/cmd/phase/list.go +++ b/cmd/phase/list.go @@ -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") } diff --git a/cmd/phase/list_test.go b/cmd/phase/list_test.go index 190e04ea6..c0d5298ed 100644 --- a/cmd/phase/list_test.go +++ b/cmd/phase/list_test.go @@ -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), }, diff --git a/cmd/phase/testdata/TestNewListCommandGoldenOutput/phase-list-cmd-with-help.golden b/cmd/phase/testdata/TestNewListCommandGoldenOutput/phase-list-cmd-with-help.golden new file mode 100644 index 000000000..dd491492f --- /dev/null +++ b/cmd/phase/testdata/TestNewListCommandGoldenOutput/phase-list-cmd-with-help.golden @@ -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 diff --git a/cmd/phase/testdata/TestNewPlanCommandGoldenOutput/phase-plan-cmd-with-help.golden b/cmd/phase/testdata/TestNewPlanCommandGoldenOutput/phase-plan-cmd-with-help.golden deleted file mode 100644 index e4c7d300c..000000000 --- a/cmd/phase/testdata/TestNewPlanCommandGoldenOutput/phase-plan-cmd-with-help.golden +++ /dev/null @@ -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 diff --git a/docs/source/cli/airshipctl_phase_list.md b/docs/source/cli/airshipctl_phase_list.md index 3c226e2e0..81464db32 100644 --- a/docs/source/cli/airshipctl_phase_list.md +++ b/docs/source/cli/airshipctl_phase_list.md @@ -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 ``` diff --git a/tools/document/validate_site_docs.sh b/tools/document/validate_site_docs.sh index a4e6c03c0..2186f098f 100755 --- a/tools/document/validate_site_docs.sh +++ b/tools/document/validate_site_docs.sh @@ -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