Skip to content

Commit

Permalink
added missing verbosity flag logic (#473)
Browse files Browse the repository at this point in the history
  • Loading branch information
neel-astro committed Dec 29, 2021
1 parent 230bc7b commit 2ac16ed
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 50 deletions.
64 changes: 36 additions & 28 deletions cmd/airflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ func newAirflowRootCmd(client *houston.Client, out io.Writer) *cobra.Command {
cmd.AddCommand(
newAirflowInitCmd(client, out),
newAirflowDeployCmd(),
newAirflowStartCmd(),
newAirflowKillCmd(),
newAirflowLogsCmd(),
newAirflowStopCmd(),
newAirflowPSCmd(),
newAirflowRunCmd(),
newAirflowStartCmd(out),
newAirflowKillCmd(out),
newAirflowLogsCmd(out),
newAirflowStopCmd(out),
newAirflowPSCmd(out),
newAirflowRunCmd(out),
)
return cmd
}
Expand All @@ -74,13 +74,13 @@ func newDevRootCmd(client *houston.Client, out io.Writer) *cobra.Command {
cmd.AddCommand(
newAirflowInitCmd(client, out),
newAirflowDeployCmd(),
newAirflowStartCmd(),
newAirflowKillCmd(),
newAirflowLogsCmd(),
newAirflowStopCmd(),
newAirflowPSCmd(),
newAirflowRunCmd(),
newAirflowUpgradeCheckCmd(),
newAirflowStartCmd(out),
newAirflowKillCmd(out),
newAirflowLogsCmd(out),
newAirflowStopCmd(out),
newAirflowPSCmd(out),
newAirflowRunCmd(out),
newAirflowUpgradeCheckCmd(out),
)
return cmd
}
Expand All @@ -93,7 +93,8 @@ func newAirflowInitCmd(client *houston.Client, out io.Writer) *cobra.Command {
Args: cobra.MaximumNArgs(1),
// ignore PersistentPreRunE of root command
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return nil
err := SetUpLogs(out, verboseLevel)
return err
},
RunE: func(cmd *cobra.Command, args []string) error {
return airflowInit(cmd, args, client, out)
Expand Down Expand Up @@ -124,15 +125,16 @@ func newAirflowDeployCmd() *cobra.Command {
return cmd
}

func newAirflowStartCmd() *cobra.Command {
func newAirflowStartCmd(out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "start",
Short: "Start an Airflow cluster locally using docker-compose",
Long: "Start an Airflow cluster locally using docker-compose",
Args: cobra.MaximumNArgs(1),
// ignore PersistentPreRunE of root command
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return nil
err := SetUpLogs(out, verboseLevel)
return err
},
PreRunE: ensureProjectDir,
RunE: airflowStart,
Expand All @@ -141,29 +143,31 @@ func newAirflowStartCmd() *cobra.Command {
return cmd
}

func newAirflowKillCmd() *cobra.Command {
func newAirflowKillCmd(out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "kill",
Short: "Kill a locally running Airflow cluster",
Long: "Kill a locally running Airflow cluster",
// ignore PersistentPreRunE of root command
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return nil
err := SetUpLogs(out, verboseLevel)
return err
},
PreRunE: ensureProjectDir,
RunE: airflowKill,
}
return cmd
}

func newAirflowLogsCmd() *cobra.Command {
func newAirflowLogsCmd(out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "logs",
Short: "Output logs for a locally running Airflow cluster",
Long: "Output logs for a locally running Airflow cluster",
// ignore PersistentPreRunE of root command
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return nil
err := SetUpLogs(out, verboseLevel)
return err
},
PreRunE: ensureProjectDir,
RunE: airflowLogs,
Expand All @@ -174,44 +178,47 @@ func newAirflowLogsCmd() *cobra.Command {
return cmd
}

func newAirflowStopCmd() *cobra.Command {
func newAirflowStopCmd(out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "stop",
Short: "Stop a locally running Airflow cluster",
Long: "Stop a locally running Airflow cluster",
// ignore PersistentPreRunE of root command
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return nil
err := SetUpLogs(out, verboseLevel)
return err
},
PreRunE: ensureProjectDir,
RunE: airflowStop,
}
return cmd
}

func newAirflowPSCmd() *cobra.Command {
func newAirflowPSCmd(out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "ps",
Short: "List locally running Airflow containers",
Long: "List locally running Airflow containers",
// ignore PersistentPreRunE of root command
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return nil
err := SetUpLogs(out, verboseLevel)
return err
},
PreRunE: ensureProjectDir,
RunE: airflowPS,
}
return cmd
}

func newAirflowRunCmd() *cobra.Command {
func newAirflowRunCmd(out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "run",
Short: "Run a command inside locally running Airflow webserver",
Long: "Run a command inside locally running Airflow webserver",
// ignore PersistentPreRunE of root command
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return nil
err := SetUpLogs(out, verboseLevel)
return err
},
PreRunE: ensureProjectDir,
RunE: airflowRun,
Expand All @@ -221,14 +228,15 @@ func newAirflowRunCmd() *cobra.Command {
return cmd
}

func newAirflowUpgradeCheckCmd() *cobra.Command {
func newAirflowUpgradeCheckCmd(out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "upgrade-check",
Short: "List DAG and config-level changes required to upgrade to Airflow 2.0",
Long: "List DAG and config-level changes required to upgrade to Airflow 2.0",
// ignore PersistentPreRunE of root command
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return nil
err := SetUpLogs(out, verboseLevel)
return err
},
PreRunE: ensureProjectDir,
RunE: airflowUpgradeCheck,
Expand Down
38 changes: 19 additions & 19 deletions cmd/airflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,37 +51,37 @@ func TestNewAirflowInitCmd(t *testing.T) {
}

func TestNewAirflowStartCmd(t *testing.T) {
cmd := newAirflowStartCmd()
cmd := newAirflowStartCmd(os.Stdout)
assert.Nil(t, cmd.PersistentPreRunE(new(cobra.Command), []string{}))
}

func TestNewAirflowKillCmd(t *testing.T) {
cmd := newAirflowKillCmd()
cmd := newAirflowKillCmd(os.Stdout)
assert.Nil(t, cmd.PersistentPreRunE(new(cobra.Command), []string{}))
}

func TestNewAirflowLogsCmd(t *testing.T) {
cmd := newAirflowLogsCmd()
cmd := newAirflowLogsCmd(os.Stdout)
assert.Nil(t, cmd.PersistentPreRunE(new(cobra.Command), []string{}))
}

func TestNewAirflowStopCmd(t *testing.T) {
cmd := newAirflowStopCmd()
cmd := newAirflowStopCmd(os.Stdout)
assert.Nil(t, cmd.PersistentPreRunE(new(cobra.Command), []string{}))
}

func TestNewAirflowPSCmd(t *testing.T) {
cmd := newAirflowPSCmd()
cmd := newAirflowPSCmd(os.Stdout)
assert.Nil(t, cmd.PersistentPreRunE(new(cobra.Command), []string{}))
}

func TestNewAirflowRunCmd(t *testing.T) {
cmd := newAirflowRunCmd()
cmd := newAirflowRunCmd(os.Stdout)
assert.Nil(t, cmd.PersistentPreRunE(new(cobra.Command), []string{}))
}

func TestNewAirflowUpgradeCheckCmd(t *testing.T) {
cmd := newAirflowUpgradeCheckCmd()
cmd := newAirflowUpgradeCheckCmd(os.Stdout)
assert.Nil(t, cmd.PersistentPreRunE(new(cobra.Command), []string{}))
}

Expand All @@ -97,7 +97,7 @@ func TestAirflowKillSuccess(t *testing.T) {
return mockContainer, nil
}

cmd := newAirflowKillCmd()
cmd := newAirflowKillCmd(os.Stdout)
err := airflowKill(cmd, []string{})
assert.NoError(t, err)
mockContainer.AssertExpectations(t)
Expand All @@ -115,7 +115,7 @@ func TestAirflowKillFailure(t *testing.T) {
return mockContainer, nil
}

cmd := newAirflowKillCmd()
cmd := newAirflowKillCmd(os.Stdout)
err := airflowKill(cmd, []string{})
assert.Error(t, err, errSomeContainerIssue.Error())
mockContainer.AssertExpectations(t)
Expand All @@ -133,7 +133,7 @@ func TestAirflowLogsSuccess(t *testing.T) {
return mockContainer, nil
}

cmd := newAirflowLogsCmd()
cmd := newAirflowLogsCmd(os.Stdout)
cmd.Flags().Set("scheduler", "true")
cmd.Flags().Set("webserver", "true")
err := airflowLogs(cmd, []string{})
Expand All @@ -153,7 +153,7 @@ func TestAirflowLogsFailure(t *testing.T) {
return mockContainer, nil
}

cmd := newAirflowLogsCmd()
cmd := newAirflowLogsCmd(os.Stdout)
err := airflowLogs(cmd, []string{})
assert.Error(t, err, errSomeContainerIssue.Error())
mockContainer.AssertExpectations(t)
Expand All @@ -171,7 +171,7 @@ func TestAirflowStopSuccess(t *testing.T) {
return mockContainer, nil
}

cmd := newAirflowStopCmd()
cmd := newAirflowStopCmd(os.Stdout)
err := airflowStop(cmd, []string{})
assert.NoError(t, err)
mockContainer.AssertExpectations(t)
Expand All @@ -189,7 +189,7 @@ func TestAirflowStopFailure(t *testing.T) {
return mockContainer, nil
}

cmd := newAirflowStopCmd()
cmd := newAirflowStopCmd(os.Stdout)
err := airflowStop(cmd, []string{})
assert.Error(t, err, errSomeContainerIssue.Error())
mockContainer.AssertExpectations(t)
Expand All @@ -207,7 +207,7 @@ func TestAirflowPSSuccess(t *testing.T) {
return mockContainer, nil
}

cmd := newAirflowPSCmd()
cmd := newAirflowPSCmd(os.Stdout)
err := airflowPS(cmd, []string{})
assert.NoError(t, err)
mockContainer.AssertExpectations(t)
Expand All @@ -225,7 +225,7 @@ func TestAirflowPSFailure(t *testing.T) {
return mockContainer, nil
}

cmd := newAirflowPSCmd()
cmd := newAirflowPSCmd(os.Stdout)
err := airflowPS(cmd, []string{})
assert.Error(t, err, errSomeContainerIssue.Error())
mockContainer.AssertExpectations(t)
Expand All @@ -243,7 +243,7 @@ func TestAirflowRunSuccess(t *testing.T) {
return mockContainer, nil
}

cmd := newAirflowRunCmd()
cmd := newAirflowRunCmd(os.Stdout)
err := airflowRun(cmd, []string{})
assert.NoError(t, err)
mockContainer.AssertExpectations(t)
Expand All @@ -261,7 +261,7 @@ func TestAirflowRunFailure(t *testing.T) {
return mockContainer, nil
}

cmd := newAirflowRunCmd()
cmd := newAirflowRunCmd(os.Stdout)
err := airflowRun(cmd, []string{})
assert.Error(t, err, errSomeContainerIssue.Error())
mockContainer.AssertExpectations(t)
Expand All @@ -279,7 +279,7 @@ func TestAirflowUpgradeCheckSuccess(t *testing.T) {
return mockContainer, nil
}

cmd := newAirflowUpgradeCheckCmd()
cmd := newAirflowUpgradeCheckCmd(os.Stdout)
err := airflowUpgradeCheck(cmd, []string{})
assert.NoError(t, err)
mockContainer.AssertExpectations(t)
Expand All @@ -297,7 +297,7 @@ func TestAirflowUpgradeCheckFailure(t *testing.T) {
return mockContainer, nil
}

cmd := newAirflowUpgradeCheckCmd()
cmd := newAirflowUpgradeCheckCmd(os.Stdout)
err := airflowUpgradeCheck(cmd, []string{})
assert.Error(t, err, errSomeContainerIssue.Error())
mockContainer.AssertExpectations(t)
Expand Down
3 changes: 2 additions & 1 deletion cmd/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ func newAuthRootCmd(client *houston.Client, out io.Writer) *cobra.Command {
cmd := &cobra.Command{
// ignore PersistentPreRunE of root command
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return nil
err := SetUpLogs(out, verboseLevel)
return err
},
Use: "auth",
Short: "Authenticate with an Astronomer Cluster",
Expand Down
6 changes: 4 additions & 2 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ func newVersionCmd(client *houston.Client, out io.Writer) *cobra.Command {
Long: "The astro-cli semantic version and git commit tied to that release.",
// ignore PersistentPreRunE of root command
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return nil
err := SetUpLogs(out, verboseLevel)
return err
},
RunE: func(cmd *cobra.Command, args []string) error {
return printVersion(client, cmd, out, args)
Expand All @@ -34,7 +35,8 @@ func newUpgradeCheckCmd(client *houston.Client, out io.Writer) *cobra.Command {
Long: "Check for newer version of Astronomer CLI",
// ignore PersistentPreRunE of root command
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return nil
err := SetUpLogs(out, verboseLevel)
return err
},
RunE: func(cmd *cobra.Command, args []string) error {
return upgradeCheck(client, cmd, out, args)
Expand Down

0 comments on commit 2ac16ed

Please sign in to comment.