diff --git a/cli/internal/new.go b/cli/internal/new.go index f8ce7fcc6..18cc11ea6 100644 --- a/cli/internal/new.go +++ b/cli/internal/new.go @@ -72,7 +72,7 @@ func createSecrets(sanitisedAppName string) (AppSecrets, error) { // ensureDomainFlag checks if the domain flag was used. if not, asks the user for it/ func ensureDomainFlag(recipe recipe.Recipe, server string) error { - if Domain == "" { + if Domain == "" && !NoInput { prompt := &survey.Input{ Message: "Specify app domain", Default: fmt.Sprintf("%s.%s", recipe.Name, server), @@ -81,6 +81,11 @@ func ensureDomainFlag(recipe recipe.Recipe, server string) error { return err } } + + if Domain == "" { + return fmt.Errorf("no domain provided") + } + return nil } @@ -91,7 +96,7 @@ func ensureServerFlag() error { return err } - if NewAppServer == "" { + if NewAppServer == "" && !NoInput { prompt := &survey.Select{ Message: "Select app server:", Options: servers, @@ -101,12 +106,16 @@ func ensureServerFlag() error { } } + if NewAppServer == "" { + return fmt.Errorf("no server provided") + } + return nil } // ensureServerFlag checks if the AppName flag was used. if not, asks the user for it. func ensureAppNameFlag() error { - if NewAppName == "" { + if NewAppName == "" && !NoInput { prompt := &survey.Input{ Message: "Specify app name:", Default: config.SanitiseAppName(Domain), @@ -115,6 +124,11 @@ func ensureAppNameFlag() error { return err } } + + if NewAppName == "" { + return fmt.Errorf("no app name provided") + } + return nil } @@ -174,7 +188,7 @@ func NewAction(c *cli.Context) error { table.Append([]string{sanitisedAppName, Domain, recipe.Name, NewAppServer}) fmt.Println("") - fmt.Println(fmt.Sprintf("New '%s' created! Here is your new app overview:", recipe.Name)) + fmt.Println(fmt.Sprintf("A new %s app has been created! Here is an overview:", recipe.Name)) fmt.Println("") table.Render() fmt.Println("") diff --git a/cli/internal/validate.go b/cli/internal/validate.go index 9c3a3d51d..59b26e301 100644 --- a/cli/internal/validate.go +++ b/cli/internal/validate.go @@ -57,7 +57,7 @@ func ValidateRecipeWithPrompt(c *cli.Context) recipe.Recipe { } } - if recipeName == "" && RecipeName != "" { + if RecipeName != "" { recipeName = RecipeName logrus.Debugf("programmatically setting recipe name to %s", recipeName) } @@ -80,7 +80,7 @@ func ValidateRecipeWithPrompt(c *cli.Context) recipe.Recipe { func ValidateApp(c *cli.Context) config.App { appName := c.Args().First() - if appName == "" && AppName != "" { + if AppName != "" { appName = AppName logrus.Debugf("programmatically setting app name to %s", appName) } diff --git a/cli/server/add.go b/cli/server/add.go index 0d0e4592d..f82763e9a 100644 --- a/cli/server/add.go +++ b/cli/server/add.go @@ -8,10 +8,12 @@ import ( "os" "os/exec" "os/user" + "path" "path/filepath" "strings" "time" + abraFormatter "coopcloud.tech/abra/cli/formatter" "coopcloud.tech/abra/cli/internal" "coopcloud.tech/abra/pkg/client" "coopcloud.tech/abra/pkg/config" @@ -331,14 +333,31 @@ func createServerDir(domainName string) error { func deployTraefik(c *cli.Context, cl *dockerClient.Client, domainName string) error { internal.NoInput = true + internal.RecipeName = "traefik" internal.NewAppServer = domainName - internal.NewAppName = config.SanitiseAppName(domainName) - if err := internal.NewAction(c); err != nil { - logrus.Fatal(err) + internal.Domain = fmt.Sprintf("%s.%s", "traefik", domainName) + internal.NewAppName = fmt.Sprintf("%s_%s", "traefik", config.SanitiseAppName(domainName)) + + appEnvPath := path.Join(config.ABRA_DIR, "servers", internal.Domain, fmt.Sprintf("%s.env", internal.NewAppName)) + if _, err := os.Stat(appEnvPath); !os.IsNotExist(err) { + fmt.Println(fmt.Sprintf(` + You specified "--traefik/-t" and that means that Abra will now try to + automatically create a new Traefik app on %s. + `, internal.NewAppServer)) + + tableCol := []string{"recipe", "domain", "server", "name"} + table := abraFormatter.CreateTable(tableCol) + table.Append([]string{internal.RecipeName, internal.Domain, internal.NewAppServer, internal.NewAppName}) + + if err := internal.NewAction(c); err != nil { + logrus.Fatal(err) + } + } else { + logrus.Infof("%s already exists, not creating again", appEnvPath) } - internal.AppName = domainName + internal.AppName = internal.NewAppName if err := internal.DeployAction(c); err != nil { logrus.Fatal(err) }