[#28] Fix bad defaults for config file paths.

This moves the management of default file paths away from pflag and
into airshipctl.

Change-Id: Ib2f701d727fdd28794980cf44722d3147d4e6f07
This commit is contained in:
Ian Howell 2020-02-10 16:25:43 -06:00
parent 6e8ca5b010
commit e42049919e
3 changed files with 21 additions and 9 deletions

View File

@ -47,7 +47,7 @@ func TestFlagLoading(t *testing.T) {
{
name: "default, no flags",
args: []string{},
expected: "$HOME/.airship/config",
expected: "",
},
{
name: "alternate airshipconfig",

View File

@ -12,4 +12,4 @@ const (
Wide = "wide"
)
const HomePlaceholder = "$HOME"
const HomeEnvVar = "$HOME"

View File

@ -24,15 +24,27 @@ type AirshipCTLSettings struct {
// InitFlags adds the default settings flags to cmd
func (a *AirshipCTLSettings) InitFlags(cmd *cobra.Command) {
flags := cmd.PersistentFlags()
flags.BoolVar(&a.Debug, "debug", false, "enable verbose output")
flags.BoolVar(
&a.Debug,
"debug",
false,
"enable verbose output")
flags.StringVar(&a.airshipConfigPath, config.FlagConfigFilePath,
filepath.Join(HomePlaceholder, config.AirshipConfigDir, config.AirshipConfig),
"Path to file for airshipctl configuration.")
defaultAirshipConfigDir := filepath.Join(HomeEnvVar, config.AirshipConfigDir)
flags.StringVar(&a.kubeConfigPath, clientcmd.RecommendedConfigPathFlag,
filepath.Join(HomePlaceholder, config.AirshipConfigDir, config.AirshipKubeConfig),
"Path to kubeconfig associated with airshipctl configuration.")
defaultAirshipConfigPath := filepath.Join(defaultAirshipConfigDir, config.AirshipConfig)
flags.StringVar(
&a.airshipConfigPath,
config.FlagConfigFilePath,
"",
`Path to file for airshipctl configuration. (default "`+defaultAirshipConfigPath+`")`)
defaultKubeConfigPath := filepath.Join(defaultAirshipConfigDir, config.AirshipKubeConfig)
flags.StringVar(
&a.kubeConfigPath,
clientcmd.RecommendedConfigPathFlag,
"",
`Path to kubeconfig associated with airshipctl configuration. (default "`+defaultKubeConfigPath+`")`)
}
func (a *AirshipCTLSettings) Config() *config.Config {