From 8c6ebb66d904c41a4993f6f99740c4ab298df083 Mon Sep 17 00:00:00 2001 From: Kostiantyn Kalynovskyi Date: Tue, 28 Jan 2020 17:16:11 +0000 Subject: [PATCH] [AIR-203] add airshipctl config init subcommand This commit is only base for future implementation Change-Id: I3cfb3508de04d0a717245a75b5b197fda68fd01c --- cmd/config/config.go | 1 + cmd/config/init.go | 41 +++++++++++++++++++ cmd/config/init_test.go | 39 ++++++++++++++++++ .../config-cmd-with-defaults.golden | 1 + .../config-cmd-with-help.golden | 1 + .../config-init.golden | 7 ++++ 6 files changed, 90 insertions(+) create mode 100644 cmd/config/init.go create mode 100644 cmd/config/init_test.go create mode 100644 cmd/config/testdata/TestConfigInitGoldenOutput/config-init.golden diff --git a/cmd/config/config.go b/cmd/config/config.go index 49e9c86b7..31d1cd2b2 100644 --- a/cmd/config/config.go +++ b/cmd/config/config.go @@ -19,6 +19,7 @@ like "airshipctl config set-current-context my-context" `), configRootCmd.AddCommand(NewCmdConfigGetCluster(rootSettings)) configRootCmd.AddCommand(NewCmdConfigSetContext(rootSettings)) configRootCmd.AddCommand(NewCmdConfigGetContext(rootSettings)) + configRootCmd.AddCommand(NewCmdConfigInit(rootSettings)) return configRootCmd } diff --git a/cmd/config/init.go b/cmd/config/init.go new file mode 100644 index 000000000..9cd437343 --- /dev/null +++ b/cmd/config/init.go @@ -0,0 +1,41 @@ +/*l +Copyright 2014 The Kubernetes Authors. + +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 + + http://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 config + +import ( + "github.com/spf13/cobra" + + "opendev.org/airship/airshipctl/pkg/environment" + "opendev.org/airship/airshipctl/pkg/errors" +) + +var ( + configInitLong = (`Generate initial configuration files for airshipctl`) +) + +// NewCmdConfigInit returns a Command instance for 'config init' sub command +func NewCmdConfigInit(rootSettings *environment.AirshipCTLSettings) *cobra.Command { + configInitCmd := &cobra.Command{ + Use: "init", + Short: configInitLong, + RunE: func(cmd *cobra.Command, args []string) error { + return errors.ErrNotImplemented{} + }, + } + + return configInitCmd +} diff --git a/cmd/config/init_test.go b/cmd/config/init_test.go new file mode 100644 index 000000000..0ce36c2de --- /dev/null +++ b/cmd/config/init_test.go @@ -0,0 +1,39 @@ +/* +Copyright 2017 The Kubernetes Authors. + +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 + + http://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 config + +import ( + "testing" + + "opendev.org/airship/airshipctl/pkg/errors" + "opendev.org/airship/airshipctl/testutil" +) + +func TestConfigInit(t *testing.T) { + cmdTests := []*testutil.CmdTest{ + { + Name: "config-init", + CmdLine: "", + Cmd: NewCmdConfigInit(nil), + Error: errors.ErrNotImplemented{}, + }, + } + + for _, tt := range cmdTests { + testutil.RunTest(t, tt) + } +} diff --git a/cmd/config/testdata/TestConfigGoldenOutput/config-cmd-with-defaults.golden b/cmd/config/testdata/TestConfigGoldenOutput/config-cmd-with-defaults.golden index 0b45f824e..301af284c 100644 --- a/cmd/config/testdata/TestConfigGoldenOutput/config-cmd-with-defaults.golden +++ b/cmd/config/testdata/TestConfigGoldenOutput/config-cmd-with-defaults.golden @@ -8,6 +8,7 @@ Available Commands: get-cluster Display a specific cluster or all defined clusters if no name is provided get-context Display a specific context, the current-context or all defined contexts if no name is provided help Help about any command + init Generate initial configuration files for airshipctl set-cluster Sets a cluster entry in the airshipctl config set-context Sets a context entry or updates current-context in the airshipctl config diff --git a/cmd/config/testdata/TestConfigGoldenOutput/config-cmd-with-help.golden b/cmd/config/testdata/TestConfigGoldenOutput/config-cmd-with-help.golden index 0b45f824e..301af284c 100644 --- a/cmd/config/testdata/TestConfigGoldenOutput/config-cmd-with-help.golden +++ b/cmd/config/testdata/TestConfigGoldenOutput/config-cmd-with-help.golden @@ -8,6 +8,7 @@ Available Commands: get-cluster Display a specific cluster or all defined clusters if no name is provided get-context Display a specific context, the current-context or all defined contexts if no name is provided help Help about any command + init Generate initial configuration files for airshipctl set-cluster Sets a cluster entry in the airshipctl config set-context Sets a context entry or updates current-context in the airshipctl config diff --git a/cmd/config/testdata/TestConfigInitGoldenOutput/config-init.golden b/cmd/config/testdata/TestConfigInitGoldenOutput/config-init.golden new file mode 100644 index 000000000..319f291f4 --- /dev/null +++ b/cmd/config/testdata/TestConfigInitGoldenOutput/config-init.golden @@ -0,0 +1,7 @@ +Error: Not implemented +Usage: + init [flags] + +Flags: + -h, --help help for init +