github.com/taubyte/tau-cli@v0.1.13-0.20240326000942-487f0d57edfc/prompts/library/repository.go (about)

     1  package libraryPrompts
     2  
     3  import (
     4  	"fmt"
     5  
     6  	structureSpec "github.com/taubyte/go-specs/structure"
     7  	"github.com/taubyte/tau-cli/common"
     8  	"github.com/taubyte/tau-cli/flags"
     9  	projectLib "github.com/taubyte/tau-cli/lib/project"
    10  	repositoryLib "github.com/taubyte/tau-cli/lib/repository"
    11  	"github.com/taubyte/tau-cli/prompts"
    12  	"github.com/taubyte/tau-cli/singletons/templates"
    13  	"github.com/urfave/cli/v2"
    14  )
    15  
    16  func RepositoryInfo(ctx *cli.Context, library *structureSpec.Library, new bool) (interface{}, error) {
    17  	if new && prompts.GetGenerateRepository(ctx) {
    18  		return repositoryInfoGenerate(ctx, library)
    19  	}
    20  
    21  	selectedRepository, err := prompts.SelectARepository(ctx, &repositoryLib.Info{
    22  		Type:     repositoryLib.LibraryRepositoryType,
    23  		FullName: library.RepoName,
    24  		ID:       library.RepoID,
    25  	})
    26  	if err != nil {
    27  		return nil, err
    28  	}
    29  
    30  	library.RepoID = selectedRepository.ID
    31  	library.RepoName = selectedRepository.FullName
    32  
    33  	projectConfig, err := projectLib.SelectedProjectConfig()
    34  	if err != nil {
    35  		return nil, err
    36  	}
    37  
    38  	if !selectedRepository.HasBeenCloned(projectConfig, library.Provider) {
    39  		selectedRepository.DoClone = prompts.GetClone(ctx)
    40  	}
    41  
    42  	return selectedRepository, nil
    43  
    44  }
    45  
    46  func repositoryInfoGenerate(ctx *cli.Context, library *structureSpec.Library) (*repositoryLib.InfoTemplate, error) {
    47  	repositoryName := fmt.Sprintf(common.LibraryRepoPrefix, library.Name)
    48  
    49  	// Skipping prompt for repository name unless set, using generated name
    50  	if ctx.IsSet(flags.RepositoryName.Name) {
    51  		repositoryName = prompts.GetOrRequireARepositoryName(ctx)
    52  	}
    53  
    54  	private := prompts.GetPrivate(ctx)
    55  
    56  	templateMap, err := templates.Get().Libraries()
    57  	if err != nil {
    58  		// TODO verbose
    59  		return nil, err
    60  	}
    61  
    62  	templateUrl, err := prompts.SelectATemplate(ctx, templateMap)
    63  	if err != nil {
    64  		return nil, err
    65  	}
    66  
    67  	return &repositoryLib.InfoTemplate{
    68  		RepositoryName: repositoryName,
    69  		Info: templates.TemplateInfo{
    70  			URL: templateUrl,
    71  			// TODO Update website template description style
    72  			// Description: library.Description,
    73  		},
    74  		Private: private,
    75  	}, nil
    76  }