github.com/Redstoneguy129/cli@v0.0.0-20230211220159-15dca4e91917/internal/hostnames/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/hostnames"
    10  	"github.com/Redstoneguy129/cli/internal/utils"
    11  )
    12  
    13  func Run(ctx context.Context, projectRefArg string, includeRawOutput bool, fsys afero.Fs) error {
    14  	// 1. Sanity checks.
    15  	projectRef := projectRefArg
    16  	{
    17  		if len(projectRefArg) == 0 {
    18  			ref, err := utils.LoadProjectRef(fsys)
    19  			if err != nil {
    20  				return err
    21  			}
    22  			projectRef = ref
    23  		} else if !utils.ProjectRefPattern.MatchString(projectRef) {
    24  			return errors.New("Invalid project ref format. Must be like `abcdefghijklmnopqrst`.")
    25  		}
    26  	}
    27  
    28  	// 2. activate custom hostname config
    29  	{
    30  		resp, err := hostnames.GetCustomHostnameConfig(ctx, projectRef)
    31  		if err != nil {
    32  			return err
    33  		}
    34  		status, err := hostnames.TranslateStatus(resp.JSON200, includeRawOutput)
    35  		if err != nil {
    36  			return err
    37  		}
    38  		fmt.Println(status)
    39  		return nil
    40  	}
    41  }