From 653a553d1c11cbb6273fc3bef0051f6835da8a73 Mon Sep 17 00:00:00 2001
From: Dmitry Ukov <dukov@mirantis.com>
Date: Fri, 4 Dec 2020 16:45:43 +0400
Subject: [PATCH] Add plan subcommand group frame

Change-Id: Ie90b88ed47fb0050b874eecadafeef3d3fc5f3b1
Relates-To: #395
Relates-To: #385
---
 cmd/phase/phase.go                            |  4 +-
 cmd/plan/list.go                              | 41 ++++++++++++++++++
 cmd/plan/list_test.go                         | 35 ++++++++++++++++
 cmd/plan/plan.go                              | 42 +++++++++++++++++++
 cmd/plan/plan_test.go                         | 35 ++++++++++++++++
 cmd/plan/run.go                               | 42 +++++++++++++++++++
 cmd/plan/run_test.go                          | 35 ++++++++++++++++
 .../plan-list-cmd-with-help.golden            |  7 ++++
 .../plan-cmd-with-help.golden                 | 15 +++++++
 .../plan-run-with-help.golden                 |  7 ++++
 cmd/root.go                                   |  2 +
 .../rootCmd-with-default-subcommands.golden   |  1 +
 docs/source/cli/airshipctl.md                 |  1 +
 docs/source/cli/airshipctl_plan.md            | 29 +++++++++++++
 docs/source/cli/airshipctl_plan_list.md       | 30 +++++++++++++
 docs/source/cli/airshipctl_plan_run.md        | 30 +++++++++++++
 16 files changed, 354 insertions(+), 2 deletions(-)
 create mode 100644 cmd/plan/list.go
 create mode 100644 cmd/plan/list_test.go
 create mode 100644 cmd/plan/plan.go
 create mode 100644 cmd/plan/plan_test.go
 create mode 100644 cmd/plan/run.go
 create mode 100644 cmd/plan/run_test.go
 create mode 100644 cmd/plan/testdata/TestNewListCommandGoldenOutput/plan-list-cmd-with-help.golden
 create mode 100644 cmd/plan/testdata/TestNewPlanCommandGoldenOutput/plan-cmd-with-help.golden
 create mode 100644 cmd/plan/testdata/TestNewRunCommandGoldenOutput/plan-run-with-help.golden
 create mode 100644 docs/source/cli/airshipctl_plan.md
 create mode 100644 docs/source/cli/airshipctl_plan_list.md
 create mode 100644 docs/source/cli/airshipctl_plan_run.md

diff --git a/cmd/phase/phase.go b/cmd/phase/phase.go
index 8d9f66902..e06668444 100644
--- a/cmd/phase/phase.go
+++ b/cmd/phase/phase.go
@@ -21,7 +21,7 @@ import (
 )
 
 const (
-	clusterLong = `
+	phaseLong = `
 This command provides capabilities for interacting with phases,
 such as getting list and applying specific one.
 `
@@ -32,7 +32,7 @@ func NewPhaseCommand(cfgFactory config.Factory) *cobra.Command {
 	phaseRootCmd := &cobra.Command{
 		Use:   "phase",
 		Short: "Manage phases",
-		Long:  clusterLong[1:],
+		Long:  phaseLong[1:],
 	}
 
 	phaseRootCmd.AddCommand(NewRenderCommand(cfgFactory))
diff --git a/cmd/plan/list.go b/cmd/plan/list.go
new file mode 100644
index 000000000..6e47e7826
--- /dev/null
+++ b/cmd/plan/list.go
@@ -0,0 +1,41 @@
+/*
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+     https://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package plan
+
+import (
+	"github.com/spf13/cobra"
+
+	"opendev.org/airship/airshipctl/pkg/config"
+	"opendev.org/airship/airshipctl/pkg/errors"
+)
+
+const (
+	listLong = `
+List life-cycle plans which were defined in document model.
+`
+)
+
+// NewListCommand creates a command which prints available phase plans
+func NewListCommand(cfgFactory config.Factory) *cobra.Command {
+	listCmd := &cobra.Command{
+		Use:   "list",
+		Short: "List plans",
+		Long:  listLong[1:],
+		RunE: func(cmd *cobra.Command, args []string) error {
+			return errors.ErrNotImplemented{What: "airshipctl plan list"}
+		},
+	}
+	return listCmd
+}
diff --git a/cmd/plan/list_test.go b/cmd/plan/list_test.go
new file mode 100644
index 000000000..245c2e6e4
--- /dev/null
+++ b/cmd/plan/list_test.go
@@ -0,0 +1,35 @@
+/*
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+     https://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package plan_test
+
+import (
+	"testing"
+
+	"opendev.org/airship/airshipctl/cmd/plan"
+	"opendev.org/airship/airshipctl/testutil"
+)
+
+func TestNewListCommand(t *testing.T) {
+	tests := []*testutil.CmdTest{
+		{
+			Name:    "plan-list-cmd-with-help",
+			CmdLine: "--help",
+			Cmd:     plan.NewListCommand(nil),
+		},
+	}
+	for _, testcase := range tests {
+		testutil.RunTest(t, testcase)
+	}
+}
diff --git a/cmd/plan/plan.go b/cmd/plan/plan.go
new file mode 100644
index 000000000..ca8e39774
--- /dev/null
+++ b/cmd/plan/plan.go
@@ -0,0 +1,42 @@
+/*
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+     https://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package plan
+
+import (
+	"github.com/spf13/cobra"
+
+	"opendev.org/airship/airshipctl/pkg/config"
+)
+
+const (
+	planLong = `
+This command provides capabilities for interacting with plan objects,
+responsible for execution phases in groups
+`
+)
+
+// NewPlanCommand creates a command for interacting with phases
+func NewPlanCommand(cfgFactory config.Factory) *cobra.Command {
+	planRootCmd := &cobra.Command{
+		Use:   "plan",
+		Short: "Manage plans",
+		Long:  planLong[1:],
+	}
+
+	planRootCmd.AddCommand(NewListCommand(cfgFactory))
+	planRootCmd.AddCommand(NewRunCommand(cfgFactory))
+
+	return planRootCmd
+}
diff --git a/cmd/plan/plan_test.go b/cmd/plan/plan_test.go
new file mode 100644
index 000000000..9e3d213c9
--- /dev/null
+++ b/cmd/plan/plan_test.go
@@ -0,0 +1,35 @@
+/*
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+     https://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package plan_test
+
+import (
+	"testing"
+
+	"opendev.org/airship/airshipctl/cmd/plan"
+	"opendev.org/airship/airshipctl/testutil"
+)
+
+func TestNewPlanCommand(t *testing.T) {
+	tests := []*testutil.CmdTest{
+		{
+			Name:    "plan-cmd-with-help",
+			CmdLine: "--help",
+			Cmd:     plan.NewPlanCommand(nil),
+		},
+	}
+	for _, testcase := range tests {
+		testutil.RunTest(t, testcase)
+	}
+}
diff --git a/cmd/plan/run.go b/cmd/plan/run.go
new file mode 100644
index 000000000..6bec3c759
--- /dev/null
+++ b/cmd/plan/run.go
@@ -0,0 +1,42 @@
+/*
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+     https://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package plan
+
+import (
+	"github.com/spf13/cobra"
+
+	"opendev.org/airship/airshipctl/pkg/config"
+	"opendev.org/airship/airshipctl/pkg/errors"
+)
+
+const (
+	runLong = `
+Run life-cycle phase plan which was defined in document model.
+`
+)
+
+// NewRunCommand creates a command which execute a particular phase plan
+func NewRunCommand(cfgFactory config.Factory) *cobra.Command {
+	listCmd := &cobra.Command{
+		Use:   "run PLAN_NAME",
+		Short: "Run plan",
+		Long:  runLong[1:],
+		Args:  cobra.ExactArgs(1),
+		RunE: func(cmd *cobra.Command, args []string) error {
+			return errors.ErrNotImplemented{What: "airshipctl plan run"}
+		},
+	}
+	return listCmd
+}
diff --git a/cmd/plan/run_test.go b/cmd/plan/run_test.go
new file mode 100644
index 000000000..8300a6273
--- /dev/null
+++ b/cmd/plan/run_test.go
@@ -0,0 +1,35 @@
+/*
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+     https://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package plan_test
+
+import (
+	"testing"
+
+	"opendev.org/airship/airshipctl/cmd/plan"
+	"opendev.org/airship/airshipctl/testutil"
+)
+
+func TestNewRunCommand(t *testing.T) {
+	tests := []*testutil.CmdTest{
+		{
+			Name:    "plan-run-with-help",
+			CmdLine: "--help",
+			Cmd:     plan.NewRunCommand(nil),
+		},
+	}
+	for _, testcase := range tests {
+		testutil.RunTest(t, testcase)
+	}
+}
diff --git a/cmd/plan/testdata/TestNewListCommandGoldenOutput/plan-list-cmd-with-help.golden b/cmd/plan/testdata/TestNewListCommandGoldenOutput/plan-list-cmd-with-help.golden
new file mode 100644
index 000000000..40b587516
--- /dev/null
+++ b/cmd/plan/testdata/TestNewListCommandGoldenOutput/plan-list-cmd-with-help.golden
@@ -0,0 +1,7 @@
+List life-cycle plans which were defined in document model.
+
+Usage:
+  list [flags]
+
+Flags:
+  -h, --help   help for list
diff --git a/cmd/plan/testdata/TestNewPlanCommandGoldenOutput/plan-cmd-with-help.golden b/cmd/plan/testdata/TestNewPlanCommandGoldenOutput/plan-cmd-with-help.golden
new file mode 100644
index 000000000..929869c54
--- /dev/null
+++ b/cmd/plan/testdata/TestNewPlanCommandGoldenOutput/plan-cmd-with-help.golden
@@ -0,0 +1,15 @@
+This command provides capabilities for interacting with plan objects,
+responsible for execution phases in groups
+
+Usage:
+  plan [command]
+
+Available Commands:
+  help        Help about any command
+  list        List plans
+  run         Run plan
+
+Flags:
+  -h, --help   help for plan
+
+Use "plan [command] --help" for more information about a command.
diff --git a/cmd/plan/testdata/TestNewRunCommandGoldenOutput/plan-run-with-help.golden b/cmd/plan/testdata/TestNewRunCommandGoldenOutput/plan-run-with-help.golden
new file mode 100644
index 000000000..96a31105e
--- /dev/null
+++ b/cmd/plan/testdata/TestNewRunCommandGoldenOutput/plan-run-with-help.golden
@@ -0,0 +1,7 @@
+Run life-cycle phase plan which was defined in document model.
+
+Usage:
+  run PLAN_NAME [flags]
+
+Flags:
+  -h, --help   help for run
diff --git a/cmd/root.go b/cmd/root.go
index 15949fa08..245f622c3 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -29,6 +29,7 @@ import (
 	"opendev.org/airship/airshipctl/cmd/document"
 	"opendev.org/airship/airshipctl/cmd/image"
 	"opendev.org/airship/airshipctl/cmd/phase"
+	"opendev.org/airship/airshipctl/cmd/plan"
 	"opendev.org/airship/airshipctl/cmd/secret"
 	cfg "opendev.org/airship/airshipctl/pkg/config"
 	"opendev.org/airship/airshipctl/pkg/log"
@@ -77,6 +78,7 @@ func AddDefaultAirshipCTLCommands(cmd *cobra.Command, factory cfg.Factory) *cobr
 	cmd.AddCommand(image.NewImageCommand(factory))
 	cmd.AddCommand(secret.NewSecretCommand(factory))
 	cmd.AddCommand(phase.NewPhaseCommand(factory))
+	cmd.AddCommand(plan.NewPlanCommand(factory))
 	cmd.AddCommand(NewVersionCommand())
 
 	return cmd
diff --git a/cmd/testdata/TestRootGoldenOutput/rootCmd-with-default-subcommands.golden b/cmd/testdata/TestRootGoldenOutput/rootCmd-with-default-subcommands.golden
index 98df51433..8625f14bc 100644
--- a/cmd/testdata/TestRootGoldenOutput/rootCmd-with-default-subcommands.golden
+++ b/cmd/testdata/TestRootGoldenOutput/rootCmd-with-default-subcommands.golden
@@ -12,6 +12,7 @@ Available Commands:
   help        Help about any command
   image       Manage ISO image creation
   phase       Manage phases
+  plan        Manage plans
   secret      Manage secrets
   version     Show the version number of airshipctl
 
diff --git a/docs/source/cli/airshipctl.md b/docs/source/cli/airshipctl.md
index 83f9bd53f..f3839709f 100644
--- a/docs/source/cli/airshipctl.md
+++ b/docs/source/cli/airshipctl.md
@@ -23,6 +23,7 @@ A unified entrypoint to various airship components
 * [airshipctl document](airshipctl_document.md)	 - Manage deployment documents
 * [airshipctl image](airshipctl_image.md)	 - Manage ISO image creation
 * [airshipctl phase](airshipctl_phase.md)	 - Manage phases
+* [airshipctl plan](airshipctl_plan.md)	 - Manage plans
 * [airshipctl secret](airshipctl_secret.md)	 - Manage secrets
 * [airshipctl version](airshipctl_version.md)	 - Show the version number of airshipctl
 
diff --git a/docs/source/cli/airshipctl_plan.md b/docs/source/cli/airshipctl_plan.md
new file mode 100644
index 000000000..a3ae9165d
--- /dev/null
+++ b/docs/source/cli/airshipctl_plan.md
@@ -0,0 +1,29 @@
+## airshipctl plan
+
+Manage plans
+
+### Synopsis
+
+This command provides capabilities for interacting with plan objects,
+responsible for execution phases in groups
+
+
+### Options
+
+```
+  -h, --help   help for plan
+```
+
+### Options inherited from parent commands
+
+```
+      --airshipconf string   Path to file for airshipctl configuration. (default "$HOME/.airship/config")
+      --debug                enable verbose output
+```
+
+### SEE ALSO
+
+* [airshipctl](airshipctl.md)	 - A unified entrypoint to various airship components
+* [airshipctl plan list](airshipctl_plan_list.md)	 - List plans
+* [airshipctl plan run](airshipctl_plan_run.md)	 - Run plan
+
diff --git a/docs/source/cli/airshipctl_plan_list.md b/docs/source/cli/airshipctl_plan_list.md
new file mode 100644
index 000000000..7c455f967
--- /dev/null
+++ b/docs/source/cli/airshipctl_plan_list.md
@@ -0,0 +1,30 @@
+## airshipctl plan list
+
+List plans
+
+### Synopsis
+
+List life-cycle plans which were defined in document model.
+
+
+```
+airshipctl plan list [flags]
+```
+
+### Options
+
+```
+  -h, --help   help for list
+```
+
+### Options inherited from parent commands
+
+```
+      --airshipconf string   Path to file for airshipctl configuration. (default "$HOME/.airship/config")
+      --debug                enable verbose output
+```
+
+### SEE ALSO
+
+* [airshipctl plan](airshipctl_plan.md)	 - Manage plans
+
diff --git a/docs/source/cli/airshipctl_plan_run.md b/docs/source/cli/airshipctl_plan_run.md
new file mode 100644
index 000000000..5d8dee53c
--- /dev/null
+++ b/docs/source/cli/airshipctl_plan_run.md
@@ -0,0 +1,30 @@
+## airshipctl plan run
+
+Run plan
+
+### Synopsis
+
+Run life-cycle phase plan which was defined in document model.
+
+
+```
+airshipctl plan run PLAN_NAME [flags]
+```
+
+### Options
+
+```
+  -h, --help   help for run
+```
+
+### Options inherited from parent commands
+
+```
+      --airshipconf string   Path to file for airshipctl configuration. (default "$HOME/.airship/config")
+      --debug                enable verbose output
+```
+
+### SEE ALSO
+
+* [airshipctl plan](airshipctl_plan.md)	 - Manage plans
+