airshipctl/cmd/config/init.go
Drew Walters 5d83122b17 [#6] Add config init subcommand
This change introduces logic for the config init subcommand, which
generates an airshipctl configuration file with default values. The
default values are extracted from constants and change when the source
code is updated.

Closes #6

Change-Id: I452e26bc5a924f0cdcd3153a9b124d23e2e5b1f0
Signed-off-by: Drew Walters <andrew.walters@att.com>
2020-02-17 16:22:10 -06:00

48 lines
1.2 KiB
Go

/*
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"
)
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 {
c := rootSettings.Config()
err := c.PersistConfig()
if err != nil {
return err
}
return nil
},
}
return configInitCmd
}