From aab98ccc18fcaa74c7c59bdb52b6b4a11fa3b7e2 Mon Sep 17 00:00:00 2001 From: Camilo Garcia La Rotta Date: Wed, 21 Jul 2021 20:06:05 -0400 Subject: [PATCH] feat: break out repo and branch surveys --- cmd/ghcs/create.go | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/cmd/ghcs/create.go b/cmd/ghcs/create.go index 35cd49a2d..cc7436e6f 100644 --- a/cmd/ghcs/create.go +++ b/cmd/ghcs/create.go @@ -53,12 +53,14 @@ func init() { rootCmd.AddCommand(newCreateCmd()) } -var createSurvey = []*survey.Question{ +var repoSurvey = []*survey.Question{ { Name: "repository", Prompt: &survey.Input{Message: "Repository"}, Validate: survey.Required, }, +} +var branchSurvey = []*survey.Question{ { Name: "branch", Prompt: &survey.Input{Message: "Branch"}, @@ -72,16 +74,19 @@ func Create() error { locationCh := getLocation(ctx, apiClient) userCh := getUser(ctx, apiClient) - answers := struct { - Repository string - Branch string - }{} - - if err := survey.Ask(createSurvey, &answers); err != nil { - return fmt.Errorf("error getting answers: %v", err) + if repo == "" { + if err := survey.Ask(repoSurvey, &repo); err != nil { + return fmt.Errorf("error getting repository name: %v", err) + } } - repository, err := apiClient.GetRepository(ctx, answers.Repository) + if branch == "" { + if err := survey.Ask(branchSurvey, &branch); err != nil { + return fmt.Errorf("error getting branch name: %v", err) + } + } + + repository, err := apiClient.GetRepository(ctx, repo) if err != nil { return fmt.Errorf("error getting repository: %v", err) } @@ -136,7 +141,7 @@ func Create() error { sku := skuByName[skuAnswers.SKU] fmt.Println("Creating your codespace...") - codespace, err := apiClient.CreateCodespace(ctx, userResult.User, repository, sku, answers.Branch, locationResult.Location) + codespace, err := apiClient.CreateCodespace(ctx, userResult.User, repository, sku, branch, locationResult.Location) if err != nil { return fmt.Errorf("error creating codespace: %v", err) }