github.com/Redstoneguy129/cli@v0.0.0-20230211220159-15dca4e91917/internal/vanity_subdomains/delete/delete.go (about)

     1  package delete
     2  
     3  import (
     4  	"context"
     5  	"errors"
     6  	"fmt"
     7  
     8  	"github.com/Redstoneguy129/cli/internal/utils"
     9  	"github.com/spf13/afero"
    10  )
    11  
    12  func Run(ctx context.Context, projectRefArg string, fsys afero.Fs) error {
    13  	// 1. Sanity checks.
    14  	projectRef := projectRefArg
    15  	{
    16  		if len(projectRefArg) == 0 {
    17  			ref, err := utils.LoadProjectRef(fsys)
    18  			if err != nil {
    19  				return err
    20  			}
    21  			projectRef = ref
    22  		} else if !utils.ProjectRefPattern.MatchString(projectRef) {
    23  			return errors.New("Invalid project ref format. Must be like `abcdefghijklmnopqrst`.")
    24  		}
    25  	}
    26  
    27  	// 2. delete config
    28  	{
    29  		resp, err := utils.GetSupabase().RemoveVanitySubdomainConfigWithResponse(ctx, projectRef)
    30  		if err != nil {
    31  			return err
    32  		}
    33  		if resp.StatusCode() != 200 {
    34  			return errors.New("failed to delete vanity subdomain config; received: " + string(resp.Body))
    35  		}
    36  		fmt.Println("Deleted vanity subdomain successfully.")
    37  		return nil
    38  	}
    39  }