diff --git a/cmd/auth.go b/cmd/auth.go index dac73bda9..160704b4b 100644 --- a/cmd/auth.go +++ b/cmd/auth.go @@ -2,10 +2,14 @@ package cmd import ( "github.com/astronomerio/astro-cli/auth" + "github.com/astronomerio/astro-cli/config" + "github.com/pkg/errors" "github.com/spf13/cobra" ) var ( + registryOverride string + authRootCmd = &cobra.Command{ Use: "auth", Short: "Mangage astronomer identity", @@ -16,7 +20,7 @@ var ( Use: "login", Short: "Login to Astronomer services", Long: "Login to Astronomer services", - Run: authLogin, + RunE: authLogin, } authLogoutCmd = &cobra.Command{ @@ -33,13 +37,23 @@ func init() { // Auth login authRootCmd.AddCommand(authLoginCmd) - + authLoginCmd.Flags().StringVarP(®istryOverride, "registry", "r", "", "pass a custom project registry for authentication") // Auth logout authRootCmd.AddCommand(authLogoutCmd) } -func authLogin(cmd *cobra.Command, args []string) { +func authLogin(cmd *cobra.Command, args []string) error { + if len(registryOverride) > 0 { + config.CFG.RegistryAuthority.SetProjectString(registryOverride) + } + + if config.CFG.RegistryAuthority.GetHomeString() == "" && + registryOverride == "" { + return errors.New("No registry set. Use -r to pass a custom registry\n\nEx.\nastro auth login -r registry.EXAMPLE_DOMAIN.com\n ") + } + auth.Login() + return nil } func authLogout(cmd *cobra.Command, args []string) {