github.com/supabase/cli@v1.168.1/internal/snippets/download/download.go (about)

     1  package download
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	"github.com/go-errors/errors"
     8  	"github.com/spf13/afero"
     9  	"github.com/supabase/cli/internal/utils"
    10  )
    11  
    12  func Run(ctx context.Context, snippetId string, fsys afero.Fs) error {
    13  	resp, err := utils.GetSupabase().GetSnippetWithResponse(ctx, snippetId)
    14  	if err != nil {
    15  		return errors.Errorf("failed to download snippet: %w", err)
    16  	}
    17  
    18  	if resp.JSON200 == nil {
    19  		return errors.New("Unexpected error downloading SQL snippet: " + string(resp.Body))
    20  	}
    21  
    22  	fmt.Println(resp.JSON200.Content.Sql)
    23  	return nil
    24  }