diff --git a/cmd/phase/phase.go b/cmd/phase/phase.go index b8155e1ce..ce7f3918d 100644 --- a/cmd/phase/phase.go +++ b/cmd/phase/phase.go @@ -39,6 +39,7 @@ func NewPhaseCommand(cfgFactory config.Factory) *cobra.Command { phaseRootCmd.AddCommand(NewListCommand(cfgFactory)) phaseRootCmd.AddCommand(NewRunCommand(cfgFactory)) phaseRootCmd.AddCommand(NewTreeCommand(cfgFactory)) + phaseRootCmd.AddCommand(NewValidateCommand(cfgFactory)) return phaseRootCmd } diff --git a/cmd/phase/testdata/TestNewPhaseCommandGoldenOutput/phase-cmd-with-help.golden b/cmd/phase/testdata/TestNewPhaseCommandGoldenOutput/phase-cmd-with-help.golden index 5b39e34b8..c2bc2804f 100644 --- a/cmd/phase/testdata/TestNewPhaseCommandGoldenOutput/phase-cmd-with-help.golden +++ b/cmd/phase/testdata/TestNewPhaseCommandGoldenOutput/phase-cmd-with-help.golden @@ -10,6 +10,7 @@ Available Commands: render Render phase documents from model run Run phase tree Tree view of kustomize entrypoints of phase + validate Assert that a phase is valid Flags: -h, --help help for phase diff --git a/cmd/phase/testdata/TestValidateGoldenOutput/validate-with-help.golden b/cmd/phase/testdata/TestValidateGoldenOutput/validate-with-help.golden new file mode 100644 index 000000000..9c34e70e9 --- /dev/null +++ b/cmd/phase/testdata/TestValidateGoldenOutput/validate-with-help.golden @@ -0,0 +1,13 @@ +Command which would validate that the phase contains the required documents to run the phase. + +Usage: + validate PHASE_NAME [flags] + +Examples: + +# validate initinfra phase +airshipctl phase validate initinfra + + +Flags: + -h, --help help for validate diff --git a/cmd/phase/validate.go b/cmd/phase/validate.go new file mode 100644 index 000000000..1e05b8986 --- /dev/null +++ b/cmd/phase/validate.go @@ -0,0 +1,54 @@ +/* + 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 phase + +import ( + "github.com/spf13/cobra" + + "opendev.org/airship/airshipctl/pkg/config" + "opendev.org/airship/airshipctl/pkg/phase" +) + +const ( + validLong = `Command which would validate that the phase contains ` + + `the required documents to run the phase. +` + + validExample = ` +# validate initinfra phase +airshipctl phase validate initinfra +` +) + +// NewValidateCommand creates a command to assert that a phase is valid is to actually run the phase. +func NewValidateCommand(cfgFactory config.Factory) *cobra.Command { + p := &phase.ValidateCommand{ + Options: phase.ValidateFlags{}, + Factory: cfgFactory, + } + validCmd := &cobra.Command{ + Use: "validate PHASE_NAME", + Short: "Assert that a phase is valid", + Long: validLong, + Args: cobra.ExactArgs(1), + Example: validExample, + RunE: func(cmd *cobra.Command, args []string) error { + p.Options.PhaseID.Name = args[0] + return p.RunE() + }, + } + + return validCmd +} diff --git a/cmd/phase/validate_test.go b/cmd/phase/validate_test.go new file mode 100644 index 000000000..be8b38721 --- /dev/null +++ b/cmd/phase/validate_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 phase_test + +import ( + "testing" + + "opendev.org/airship/airshipctl/cmd/phase" + "opendev.org/airship/airshipctl/testutil" +) + +func TestValidate(t *testing.T) { + tests := []*testutil.CmdTest{ + { + Name: "validate-with-help", + CmdLine: "-h", + Cmd: phase.NewValidateCommand(nil), + }, + } + for _, tt := range tests { + testutil.RunTest(t, tt) + } +} diff --git a/docs/source/cli/airshipctl_phase.md b/docs/source/cli/airshipctl_phase.md index 32a4904a5..635aa3948 100644 --- a/docs/source/cli/airshipctl_phase.md +++ b/docs/source/cli/airshipctl_phase.md @@ -28,4 +28,5 @@ such as getting list and applying specific one. * [airshipctl phase render](airshipctl_phase_render.md) - Render phase documents from model * [airshipctl phase run](airshipctl_phase_run.md) - Run phase * [airshipctl phase tree](airshipctl_phase_tree.md) - Tree view of kustomize entrypoints of phase +* [airshipctl phase validate](airshipctl_phase_validate.md) - Validate phase diff --git a/docs/source/cli/airshipctl_phase_validate.md b/docs/source/cli/airshipctl_phase_validate.md new file mode 100644 index 000000000..687af7e9e --- /dev/null +++ b/docs/source/cli/airshipctl_phase_validate.md @@ -0,0 +1,38 @@ +## airshipctl phase validate + +Assert that a phase is valid + +### Synopsis + +Command which would validate that the phase contains the required documents to run the phase + +``` +airshipctl phase validate PHASE_NAME [flags] +``` + +### Examples + +``` + +# validate initinfra phase +airshipctl phase validate initinfra + +``` + +### 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 phase](airshipctl_phase.md) - Manage phases +