diff --git a/cmd/airflow.go b/cmd/airflow.go index a67742f5f..eb979691a 100644 --- a/cmd/airflow.go +++ b/cmd/airflow.go @@ -18,7 +18,6 @@ import ( "github.com/astronomer/astro-cli/airflow" "github.com/astronomer/astro-cli/config" "github.com/astronomer/astro-cli/pkg/fileutil" - "github.com/astronomer/astro-cli/pkg/git" ) var ( @@ -57,7 +56,10 @@ astro airflow run create_user -r Admin -u admin -e admin@example.com -f admin -l Long: "Deploy an airflow project to a given deployment", Args: cobra.MaximumNArgs(1), PreRunE: ensureProjectDir, - RunE: airflowDeploy, + Run: func(cmd *cobra.Command, args []string) { + deployCmd.Run(cmd, args) + }, + Deprecated: "Please use new command instead `astro deploy DEPLOYMENT [flags]`", } airflowStartCmd = &cobra.Command{ @@ -123,7 +125,7 @@ func init() { // Airflow deploy airflowRootCmd.AddCommand(airflowDeployCmd) - airflowDeployCmd.Flags().BoolVarP(&forceDeploy, "force", "f", false, "Force deploy if uncommited changes") + airflowDeployCmd.Flags().BoolVarP(&forceDeploy, "force", "f", false, "Force deploy if uncommitted changes") airflowDeployCmd.Flags().BoolVarP(&forcePrompt, "prompt", "p", false, "Force prompt to choose target deployment") airflowDeployCmd.Flags().BoolVarP(&saveDeployConfig, "save", "s", false, "Save deployment in config for future deploys") airflowDeployCmd.Flags().StringVar(&workspaceId, "workspace-id", "", "workspace assigned to deployment") @@ -228,36 +230,6 @@ func airflowInit(cmd *cobra.Command, args []string) error { return nil } -func airflowDeploy(cmd *cobra.Command, args []string) error { - ws, err := coalesceWorkspace() - if err != nil { - return errors.Wrap(err, "failed to find a valid workspace") - // fmt.Println("Default workspace id not set, set default workspace id or pass a workspace in via the --workspace-id flag") - } - - releaseName := "" - - // Get release name from args, if passed - if len(args) > 0 { - releaseName = args[0] - } - - // Save releasename in config if specified - if len(releaseName) > 0 && saveDeployConfig { - config.CFG.ProjectDeployment.SetProjectString(releaseName) - } - - if git.HasUncommitedChanges() && !forceDeploy { - fmt.Println(messages.REGISTRY_UNCOMMITTED_CHANGES) - return nil - } - - // Silence Usage as we have now validated command input - cmd.SilenceUsage = true - - return airflow.Deploy(config.WorkingPath, releaseName, ws, forcePrompt) -} - // Start an airflow cluster func airflowStart(cmd *cobra.Command, args []string) error { // Silence Usage as we have now validated command input diff --git a/cmd/deploy.go b/cmd/deploy.go new file mode 100644 index 000000000..072caa5aa --- /dev/null +++ b/cmd/deploy.go @@ -0,0 +1,62 @@ +package cmd + +import ( + "fmt" + + "github.com/astronomer/astro-cli/airflow" + "github.com/astronomer/astro-cli/config" + "github.com/astronomer/astro-cli/messages" + "github.com/astronomer/astro-cli/pkg/git" + "github.com/pkg/errors" + "github.com/spf13/cobra" +) + +var ( + deployCmd = &cobra.Command{ + Use: "deploy DEPLOYMENT", + Short: "Deploy an airflow project", + Long: "Deploy an airflow project to a given deployment", + Args: cobra.MaximumNArgs(1), + PreRunE: ensureProjectDir, + RunE: deploy, + Aliases: []string{"airflow deploy"}, + } +) + +func init() { + RootCmd.AddCommand(deployCmd) + deployCmd.Flags().BoolVarP(&forceDeploy, "force", "f", false, "Force deploy if uncommitted changes") + deployCmd.Flags().BoolVarP(&forcePrompt, "prompt", "p", false, "Force prompt to choose target deployment") + deployCmd.Flags().BoolVarP(&saveDeployConfig, "save", "s", false, "Save deployment in config for future deploys") + deployCmd.Flags().StringVar(&workspaceId, "workspace-id", "", "workspace assigned to deployment") +} + +func deploy(cmd *cobra.Command, args []string) error { + ws, err := coalesceWorkspace() + if err != nil { + return errors.Wrap(err, "failed to find a valid workspace") + // fmt.Println("Default workspace id not set, set default workspace id or pass a workspace in via the --workspace-id flag") + } + + releaseName := "" + + // Get release name from args, if passed + if len(args) > 0 { + releaseName = args[0] + } + + // Save release name in config if specified + if len(releaseName) > 0 && saveDeployConfig { + config.CFG.ProjectDeployment.SetProjectString(releaseName) + } + + if git.HasUncommitedChanges() && !forceDeploy { + fmt.Println(messages.REGISTRY_UNCOMMITTED_CHANGES) + return nil + } + + // Silence Usage as we have now validated command input + cmd.SilenceUsage = true + + return airflow.Deploy(config.WorkingPath, releaseName, ws, forcePrompt) +}