func VerifyInit(cmd *cobra.Command, args []string, home string, output terminal.Outputer) error {
	_, err := config.Load(home)
	if errors.Is(err, config.ErrNoConfigFile) {
		output.Info("Warning:", err.Error())
		init, err := output.Confirm("Run `nitro init` now to create the config?", true, "")
		if err != nil {
			return err
		}
		if !init {
			return fmt.Errorf("You must run `nitro init` in order to add a site.")
		}
		for _, c := range cmd.Root().Commands() {
			if c.Use == "init" {
				if err := c.RunE(c, args); err != nil {
					return err
				}
			}
		}
	}
	return nil
}
VerifyInit is used to verify the init command has been run by checking if a config file exists.
package prompt
import (
	"context"
	"errors"
	"fmt"
	"os"
	"path/filepath"
	"sort"
	"strings"
	"github.com/craftcms/nitro/pkg/config"
	"github.com/craftcms/nitro/pkg/containerlabels"
	"github.com/craftcms/nitro/pkg/phpversions"
	"github.com/craftcms/nitro/pkg/terminal"
	"github.com/craftcms/nitro/pkg/validate"
	"github.com/craftcms/nitro/pkg/webroot"
	"github.com/docker/docker/api/types"
	"github.com/docker/docker/api/types/filters"
	"github.com/docker/docker/client"
	"github.com/spf13/cobra"
)
func CreateDatabase(cmd *cobra.Command, docker client.CommonAPIClient, output terminal.Outputer) (bool, string, string, string, string, error) {
	confirm, err := output.Confirm("Add a database for the site?", true, "")
	if err != nil {
		return false, "", "", "", "", err
	}
	if !confirm {
		return false, "", "", "", "", nil
	}
	ctx := cmd.Context()
	if ctx == nil {
		ctx = context.Background()
	}
	filter := filters.NewArgs()
	filter.Add("label", containerlabels.Nitro)
	filter.Add("label", containerlabels.Type+"=database")
	containers, err := docker.ContainerList(ctx, types.ContainerListOptions{Filters: filter, All: true})
	if err != nil {
		return false, "", "", "", "", err
	}
	sort.SliceStable(containers, func(i, j int) bool {
		return containers[i].Names[0] < containers[j].Names[0]
	})
	var engineOpts []string
	for _, c := range containers {
		if c.State != "running" {
			for _, command := range cmd.Root().Commands() {
				if command.Use == "start" {
					if err := command.RunE(cmd, []string{}); err != nil {
						return false, "", "", "", "", err
					}
				}
			}
		}
		engineOpts = append(engineOpts, strings.TrimLeft(c.Names[0], "/"))
	}
	var containerID, databaseEngine string
	selected, err := output.Select(os.Stdin, "Select the database engine: ", engineOpts)
	if err != nil {
		return false, "", "", "", "", err
	}
	containerID = containers[selected].ID
	databaseEngine = containers[selected].Labels[containerlabels.DatabaseCompatibility]
	if containerID == "" {
		return false, "", "", "", "", fmt.Errorf("unable to get the container")
	}
	db, err := output.Ask("Enter the new database name", "", ":", &validate.DatabaseName{})
	if err != nil {
		return false, "", "", "", "", err
	}
	output.Pending("creating database", db)
	var cmds, privileges []string
	switch databaseEngine {
	case "mysql":
		cmds = []string{"mysql", "-uroot", "-pnitro", fmt.Sprintf(`-e CREATE DATABASE IF NOT EXISTS %s;`, db)}
		privileges = []string{"mysql", "-uroot", "-pnitro", fmt.Sprintf(`-e GRANT ALL PRIVILEGES ON * TO '%s'@'%s';`, "nitro", "%")}
	default:
		cmds = []string{"psql", "--username=nitro", "--host=127.0.0.1", fmt.Sprintf(`-c CREATE DATABASE %s;`, db)}
	}
	e, err := docker.ContainerExecCreate(ctx, containerID, types.ExecConfig{
		AttachStdout: true,
		AttachStderr: true,
		Tty:          false,
		Cmd:          cmds,
	})
	if err != nil {
		return false, "", "", "", "", err
	}
	resp, err := docker.ContainerExecAttach(ctx, e.ID, types.ExecStartCheck{
		Tty: false,
	})
	if err != nil {
		return false, "", "", "", "", err
	}
	defer resp.Close()
	if err := docker.ContainerExecStart(ctx, e.ID, types.ExecStartCheck{}); err != nil {
		return false, "", "", "", "", fmt.Errorf("unable to start the container, %w", err)
	}
	if privileges != nil {
		e, err := docker.ContainerExecCreate(ctx, containerID, types.ExecConfig{
			AttachStdout: true,
			AttachStderr: true,
			Tty:          false,
			Cmd:          privileges,
		})
		if err != nil {
			return false, "", "", "", "", err
		}
		resp, err := docker.ContainerExecAttach(ctx, e.ID, types.ExecStartCheck{
			Tty: false,
		})
		if err != nil {
			return false, "", "", "", "", err
		}
		defer resp.Close()
		if err := docker.ContainerExecStart(ctx, e.ID, types.ExecStartCheck{}); err != nil {
			return false, "", "", "", "", fmt.Errorf("unable to start the container, %w", err)
		}
		waiting := true
		for waiting {
			resp, err := docker.ContainerExecInspect(ctx, e.ID)
			if err != nil {
				return false, "", "", "", "", err
			}
			waiting = resp.Running
		}
	}
	output.Done()
	output.Info("Database added 💪")
	hostname := strings.TrimLeft(containers[selected].Names[0], "/")
	info, err := docker.ContainerInspect(ctx, containers[selected].ID)
	if err != nil {
		return false, "", "", "", "", err
	}
	var port string
	for p := range info.NetworkSettings.Ports {
		if port != "" {
			break
		}
		port = p.Port()
	}
	driver := "mysql"
	if containers[selected].Labels[containerlabels.DatabaseCompatibility] == "postgres" {
		driver = "pgsql"
	}
	return true, hostname, db, port, driver, nil
}
func CreateSite(home, dir string, output terminal.Outputer) (*config.Site, error) {
	site := config.Site{}
	sp := strings.Split(filepath.Join(dir), string(os.PathSeparator))
	site.Hostname = sp[len(sp)-1]
	if !strings.Contains(site.Hostname, ".") {
		tld := "nitro"
		if os.Getenv("NITRO_DEFAULT_TLD") != "" {
			tld = os.Getenv("NITRO_DEFAULT_TLD")
		}
		site.Hostname = fmt.Sprintf("%s.%s", site.Hostname, tld)
	}
	hostname, err := output.Ask("Enter the hostname", site.Hostname, ":", &validate.HostnameValidator{})
	if err != nil {
		return nil, err
	}
	site.Hostname = hostname
	output.Success("setting hostname to", site.Hostname)
	siteAbsPath, err := filepath.Abs(dir)
	if err != nil {
		return nil, err
	}
	site.Path = strings.Replace(siteAbsPath, home, "~", 1)
	output.Success("adding site", site.Path)
	found, _ := webroot.Find(dir)
	if found == "" {
		found = "web"
	}
	site.Webroot = found
	root, err := output.Ask("Enter the web root for the site", site.Webroot, ":", nil)
	if err != nil {
		return nil, err
	}
	site.Webroot = root
	output.Success("using web root", site.Webroot)
	versions := phpversions.Versions
	selected, err := output.Select(os.Stdin, "Choose a PHP version: ", versions)
	if err != nil {
		return nil, err
	}
	site.Version = versions[selected]
	output.Success("setting PHP version", site.Version)
	cfg, err := config.Load(home)
	if err != nil {
		return nil, err
	}
	if err := cfg.AddSite(site); err != nil {
		return nil, err
	}
	if err := cfg.Save(); err != nil {
		return nil, err
	}
	return &site, nil
}
func RunApply(cmd *cobra.Command, args []string, force bool, output terminal.Outputer) error {
	if !force {
		apply, err := output.Confirm("Apply changes now?", true, "")
		if err != nil {
			return err
		}
		if !apply {
			return nil
		}
	}
	for _, c := range cmd.Root().Commands() {
		if c.Use == "apply" {
			if err := c.RunE(c, args); err != nil {
				return err
			}
			return c.PostRunE(c, args)
		}
	}
	return nil
}