github.com/Redstoneguy129/cli@v0.0.0-20230211220159-15dca4e91917/internal/hostnames/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().RemoveCustomHostnameConfigWithResponse(ctx, projectRef) 30 if err != nil { 31 return err 32 } 33 if resp.StatusCode() != 200 { 34 return errors.New("failed to delete custom hostname config; received: " + resp.Status()) 35 } 36 fmt.Println("Deleted custom hostname config successfully.") 37 return nil 38 } 39 }