github.com/taubyte/tau-cli@v0.1.13-0.20240326000942-487f0d57edfc/cli/commands/resources/repository/clone.go (about)

     1  package repositoryCommands
     2  
     3  import (
     4  	"github.com/taubyte/tau-cli/cli/common"
     5  	"github.com/taubyte/tau-cli/flags"
     6  	"github.com/taubyte/tau-cli/prompts"
     7  	"github.com/urfave/cli/v2"
     8  )
     9  
    10  func (lib *repositoryCommands) CloneCmd() common.Command {
    11  	return common.Create(
    12  		&cli.Command{
    13  			Flags: flags.Combine(
    14  				flags.EmbedToken,
    15  				flags.Branch,
    16  			),
    17  			Action: lib.Clone,
    18  		},
    19  	)
    20  }
    21  
    22  func (lib *repositoryCommands) Clone(ctx *cli.Context) error {
    23  	project, resource, info, err := lib.selectResource(ctx)
    24  	if err != nil {
    25  		return err
    26  	}
    27  
    28  	_, err = info.Clone(project, resource.Get().RepositoryURL(), resource.Get().Branch(), prompts.GetOrAskForEmbedToken(ctx))
    29  	if err != nil {
    30  		return err
    31  	}
    32  
    33  	err = ctx.Set("name", resource.Get().Name())
    34  	if err != nil {
    35  		return err
    36  	}
    37  
    38  	return lib.Checkout(ctx)
    39  }