github.com/taubyte/tau-cli@v0.1.13-0.20240326000942-487f0d57edfc/cli/commands/resources/repository/checkout.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) CheckoutCmd() common.Command { 11 return common.Create( 12 &cli.Command{ 13 Flags: []cli.Flag{ 14 flags.Branch, 15 }, 16 Action: lib.Checkout, 17 }, 18 ) 19 } 20 21 func (lib *repositoryCommands) Checkout(ctx *cli.Context) error { 22 project, resource, info, err := lib.selectResource(ctx) 23 if err != nil { 24 return err 25 } 26 27 repo, err := info.Open(project, resource.Get().RepositoryURL()) 28 if err != nil { 29 return err 30 } 31 32 branch, err := prompts.SelectABranch(ctx, repo) 33 if err != nil { 34 return err 35 } 36 37 err = repo.Checkout(branch) 38 if err != nil { 39 return err 40 } 41 lib.I18nCheckedOut(resource.Get().RepositoryURL(), branch) 42 43 return nil 44 }