diff --git a/cmd/baremetal/baremetal.go b/cmd/baremetal/baremetal.go index 1b0b19539..4929269e5 100644 --- a/cmd/baremetal/baremetal.go +++ b/cmd/baremetal/baremetal.go @@ -18,6 +18,7 @@ import ( "github.com/spf13/cobra" "opendev.org/airship/airshipctl/pkg/environment" + "opendev.org/airship/airshipctl/pkg/log" "opendev.org/airship/airshipctl/pkg/remote" ) @@ -36,33 +37,39 @@ const ( // NewBaremetalCommand creates a new command for interacting with baremetal using airshipctl. func NewBaremetalCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command { - cmd := &cobra.Command{ + baremetalRootCmd := &cobra.Command{ Use: "baremetal", Short: "Perform actions on baremetal hosts", + PersistentPreRun: func(cmd *cobra.Command, args []string) { + log.Init(rootSettings.Debug, cmd.OutOrStderr()) + + // Load or Initialize airship Config + rootSettings.InitConfig() + }, } ejectMediaCmd := NewEjectMediaCommand(rootSettings) - cmd.AddCommand(ejectMediaCmd) + baremetalRootCmd.AddCommand(ejectMediaCmd) isoGenCmd := NewISOGenCommand(rootSettings) - cmd.AddCommand(isoGenCmd) + baremetalRootCmd.AddCommand(isoGenCmd) powerOffCmd := NewPowerOffCommand(rootSettings) - cmd.AddCommand(powerOffCmd) + baremetalRootCmd.AddCommand(powerOffCmd) powerOnCmd := NewPowerOnCommand(rootSettings) - cmd.AddCommand(powerOnCmd) + baremetalRootCmd.AddCommand(powerOnCmd) powerStatusCmd := NewPowerStatusCommand(rootSettings) - cmd.AddCommand(powerStatusCmd) + baremetalRootCmd.AddCommand(powerStatusCmd) rebootCmd := NewRebootCommand(rootSettings) - cmd.AddCommand(rebootCmd) + baremetalRootCmd.AddCommand(rebootCmd) remoteDirectCmd := NewRemoteDirectCommand(rootSettings) - cmd.AddCommand(remoteDirectCmd) + baremetalRootCmd.AddCommand(remoteDirectCmd) - return cmd + return baremetalRootCmd } // getHostSelections builds a list of selectors that can be passed to a manager using the name and label flags passed to diff --git a/cmd/cluster/cluster.go b/cmd/cluster/cluster.go index fd51bd6c1..23e6146d3 100644 --- a/cmd/cluster/cluster.go +++ b/cmd/cluster/cluster.go @@ -18,6 +18,7 @@ import ( "github.com/spf13/cobra" "opendev.org/airship/airshipctl/pkg/environment" + "opendev.org/airship/airshipctl/pkg/log" ) const ( @@ -34,6 +35,12 @@ func NewClusterCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Comm Use: "cluster", Short: "Manage Kubernetes clusters", Long: clusterLong[1:], + PersistentPreRun: func(cmd *cobra.Command, args []string) { + log.Init(rootSettings.Debug, cmd.OutOrStderr()) + + // Load or Initialize airship Config + rootSettings.InitConfig() + }, } clusterRootCmd.AddCommand(NewInitInfraCommand(rootSettings)) diff --git a/cmd/config/config.go b/cmd/config/config.go index 60b28885f..234e1039d 100644 --- a/cmd/config/config.go +++ b/cmd/config/config.go @@ -18,6 +18,7 @@ import ( "github.com/spf13/cobra" "opendev.org/airship/airshipctl/pkg/environment" + "opendev.org/airship/airshipctl/pkg/log" ) // NewConfigCommand creates a command for interacting with the airshipctl configuration. @@ -26,6 +27,12 @@ func NewConfigCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Comma Use: "config", DisableFlagsInUseLine: true, Short: "Manage the airshipctl config file", + PersistentPreRun: func(cmd *cobra.Command, args []string) { + log.Init(rootSettings.Debug, cmd.OutOrStderr()) + + // Load or Initialize airship Config + rootSettings.InitConfig() + }, } configRootCmd.AddCommand(NewSetClusterCommand(rootSettings)) configRootCmd.AddCommand(NewGetClusterCommand(rootSettings)) diff --git a/cmd/document/document.go b/cmd/document/document.go index c151b0631..b355dd205 100644 --- a/cmd/document/document.go +++ b/cmd/document/document.go @@ -18,6 +18,7 @@ import ( "github.com/spf13/cobra" "opendev.org/airship/airshipctl/pkg/environment" + "opendev.org/airship/airshipctl/pkg/log" ) // NewDocumentCommand creates a new command for managing airshipctl documents @@ -25,6 +26,12 @@ func NewDocumentCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Com documentRootCmd := &cobra.Command{ Use: "document", Short: "Manage deployment documents", + PersistentPreRun: func(cmd *cobra.Command, args []string) { + log.Init(rootSettings.Debug, cmd.OutOrStderr()) + + // Load or Initialize airship Config + rootSettings.InitConfig() + }, } documentRootCmd.AddCommand(NewPullCommand(rootSettings)) diff --git a/cmd/phase/phase.go b/cmd/phase/phase.go index c74d5f069..8d7673528 100644 --- a/cmd/phase/phase.go +++ b/cmd/phase/phase.go @@ -19,6 +19,7 @@ import ( "opendev.org/airship/airshipctl/pkg/environment" "opendev.org/airship/airshipctl/pkg/k8s/client" + "opendev.org/airship/airshipctl/pkg/log" ) const ( @@ -34,6 +35,12 @@ func NewPhaseCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Comman Use: "phase", Short: "Manage phases", Long: clusterLong[1:], + PersistentPreRun: func(cmd *cobra.Command, args []string) { + log.Init(rootSettings.Debug, cmd.OutOrStderr()) + + // Load or Initialize airship Config + rootSettings.InitConfig() + }, } phaseRootCmd.AddCommand(NewApplyCommand(rootSettings, client.DefaultClient)) diff --git a/cmd/root.go b/cmd/root.go index 96c9958c8..370816fee 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -30,7 +30,6 @@ import ( "opendev.org/airship/airshipctl/cmd/phase" "opendev.org/airship/airshipctl/cmd/secret" "opendev.org/airship/airshipctl/pkg/environment" - "opendev.org/airship/airshipctl/pkg/log" ) // NewAirshipCTLCommand creates a root `airshipctl` command with the default commands attached @@ -48,12 +47,6 @@ func NewRootCommand(out io.Writer) (*cobra.Command, *environment.AirshipCTLSetti Short: "A unified entrypoint to various airship components", SilenceErrors: true, SilenceUsage: true, - PersistentPreRun: func(cmd *cobra.Command, args []string) { - log.Init(settings.Debug, cmd.OutOrStderr()) - - // Load or Initialize airship Config - settings.InitConfig() - }, } rootCmd.SetOut(out) rootCmd.AddCommand(NewVersionCommand())