From 9e815ffea9a703afad31661e485190dd904f5eec Mon Sep 17 00:00:00 2001 From: Greg Neiheisel <1036482+schnie@users.noreply.github.com> Date: Fri, 20 Dec 2024 14:01:31 -0500 Subject: [PATCH] Reorganize PersistentRunE hooks --- airflow/docker_test.go | 12 ------------ cmd/airflow.go | 9 ++++++--- cmd/airflow_hooks.go | 5 ----- cmd/root.go | 2 +- cmd/root_hooks.go | 4 ++-- 5 files changed, 9 insertions(+), 23 deletions(-) diff --git a/airflow/docker_test.go b/airflow/docker_test.go index 7eb708864..a18dcdc15 100644 --- a/airflow/docker_test.go +++ b/airflow/docker_test.go @@ -490,18 +490,6 @@ func (s *Suite) TestDockerComposeStart() { composeMock.AssertExpectations(s.T()) }) - s.Run("project already running", func() { - composeMock := new(mocks.DockerComposeAPI) - composeMock.On("Ps", mock.Anything, mockDockerCompose.projectName, api.PsOptions{All: true}).Return([]api.ContainerSummary{{ID: "test-webserver-id", State: "running"}}, nil).Once() - - mockDockerCompose.composeService = composeMock - - err := mockDockerCompose.Start("", "", "", "", false, false, waitTime, nil) - s.Contains(err.Error(), "cannot start, project already running") - - composeMock.AssertExpectations(s.T()) - }) - s.Run("compose ps failure", func() { composeMock := new(mocks.DockerComposeAPI) composeMock.On("Ps", mock.Anything, mockDockerCompose.projectName, api.PsOptions{All: true}).Return([]api.ContainerSummary{}, errMockDocker).Once() diff --git a/cmd/airflow.go b/cmd/airflow.go index ff3bdd0da..6f56dcaa9 100644 --- a/cmd/airflow.go +++ b/cmd/airflow.go @@ -9,13 +9,13 @@ import ( "strings" "time" - "github.com/astronomer/astro-cli/airflow/runtimes" - "github.com/astronomer/astro-cli/airflow" + "github.com/astronomer/astro-cli/airflow/runtimes" airflowversions "github.com/astronomer/astro-cli/airflow_versions" astrocore "github.com/astronomer/astro-cli/astro-client-core" astroplatformcore "github.com/astronomer/astro-cli/astro-client-platform-core" "github.com/astronomer/astro-cli/cloud/environment" + "github.com/astronomer/astro-cli/cmd/utils" "github.com/astronomer/astro-cli/config" "github.com/astronomer/astro-cli/context" "github.com/astronomer/astro-cli/houston" @@ -130,7 +130,10 @@ func newDevRootCmd(platformCoreClient astroplatformcore.CoreClient, astroCoreCli // so we set that configuration in this persistent pre-run hook. // A few sub-commands don't require this, so they explicitly // clobber it with a no-op function. - PersistentPreRunE: ConfigureContainerRuntime, + PersistentPreRunE: utils.ChainRunEs( + SetupLogging, + ConfigureContainerRuntime, + ), } cmd.AddCommand( newAirflowInitCmd(), diff --git a/cmd/airflow_hooks.go b/cmd/airflow_hooks.go index d2172c164..743d108f2 100644 --- a/cmd/airflow_hooks.go +++ b/cmd/airflow_hooks.go @@ -6,7 +6,6 @@ import ( "path/filepath" "github.com/astronomer/astro-cli/airflow/runtimes" - softwareCmd "github.com/astronomer/astro-cli/cmd/software" "github.com/astronomer/astro-cli/cmd/utils" "github.com/astronomer/astro-cli/config" "github.com/spf13/cobra" @@ -29,10 +28,6 @@ func ConfigureContainerRuntime(_ *cobra.Command, _ []string) error { if err != nil { return err } - - if err := softwareCmd.SetUpLogs(os.Stdout, verboseLevel); err != nil { - return err - } return nil } diff --git a/cmd/root.go b/cmd/root.go index 30f4ef49d..d5b3d78c2 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -66,7 +66,7 @@ func NewRootCmd() *cobra.Command { Welcome to the Astro CLI, the modern command line interface for data orchestration. You can use it for Astro, Astronomer Software, or Local Development.`, PersistentPreRunE: utils.ChainRunEs( - SetupLoggingPersistentPreRunE, + SetupLogging, CreateRootPersistentPreRunE(astroCoreClient, platformCoreClient), ), } diff --git a/cmd/root_hooks.go b/cmd/root_hooks.go index 640ebc540..b97606c01 100644 --- a/cmd/root_hooks.go +++ b/cmd/root_hooks.go @@ -18,9 +18,9 @@ import ( "github.com/spf13/cobra" ) -// SetupLoggingPersistentPreRunE is a pre-run hook shared between software & cloud +// SetupLogging is a pre-run hook shared between software & cloud // setting up log verbosity. -func SetupLoggingPersistentPreRunE(_ *cobra.Command, _ []string) error { +func SetupLogging(_ *cobra.Command, _ []string) error { return softwareCmd.SetUpLogs(os.Stdout, verboseLevel) }