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

     1  package get
     2  
     3  import (
     4  	"context"
     5  	"errors"
     6  	"fmt"
     7  
     8  	"github.com/spf13/afero"
     9  	"github.com/Redstoneguy129/cli/internal/utils"
    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. get vanity subdomain config
    28  	{
    29  		response, err := utils.GetSupabase().GetVanitySubdomainConfigWithResponse(ctx, projectRef)
    30  		if err != nil {
    31  			return err
    32  		}
    33  		if response.JSON200 == nil {
    34  			return fmt.Errorf("failed to obtain vanity subdomain config: %+v", string(response.Body))
    35  		}
    36  		fmt.Printf("Status: %s\n", response.JSON200.Status)
    37  		if response.JSON200.CustomDomain != nil {
    38  			fmt.Printf("Vanity subdomain: %s\n", *response.JSON200.CustomDomain)
    39  		}
    40  		return nil
    41  	}
    42  }