From 130c5262b29f88ad3346ba7c736a596c1d2816b0 Mon Sep 17 00:00:00 2001 From: ShubhankarKG Date: Tue, 18 Aug 2020 16:23:16 +0530 Subject: [PATCH] Refactor changes --- pkg/cmd/repo/create/create.go | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/pkg/cmd/repo/create/create.go b/pkg/cmd/repo/create/create.go index 6dded0159..5abd9a96f 100644 --- a/pkg/cmd/repo/create/create.go +++ b/pkg/cmd/repo/create/create.go @@ -99,10 +99,11 @@ func createRun(opts *CreateOptions) error { isDescEmpty := opts.Description == "" isVisibilityPassed := false - if name != "" { + if opts.Name != "" { isNameAnArg = true - if strings.Contains(name, "/") { - newRepo, err := ghrepo.FromFullName(name) + if strings.Contains(opts.Name, "/") { + var err error + repoToCreate, err = ghrepo.FromFullName(opts.Name) if err != nil { return fmt.Errorf("argument error: %w", err) } @@ -139,12 +140,12 @@ func createRun(opts *CreateOptions) error { // Trigger interactive prompt if name is not passed if !isNameAnArg { - newName, newDesc, newVisibility, err := interactiveRepoCreate(isDescEmpty, isVisibilityPassed, name) + newName, newDesc, newVisibility, err := interactiveRepoCreate(isDescEmpty, isVisibilityPassed, repoToCreate.RepoName()) if err != nil { return err } if newName != "" { - name = newName + opts.Name = newName } if newDesc != "" { opts.Description = newDesc @@ -187,7 +188,7 @@ func createRun(opts *CreateOptions) error { } if opts.ConfirmSubmit { - repo, err := repoCreate(httpClient, input) + repo, err := repoCreate(httpClient, repoToCreate.RepoHost(), input) if err != nil { return err } @@ -208,7 +209,7 @@ func createRun(opts *CreateOptions) error { if err != nil { return err } - protocol, err := cfg.Get("", "git_protocol") + protocol, err := cfg.Get(repo.RepoHost(), "git_protocol") if err != nil { return err } @@ -248,7 +249,7 @@ func createRun(opts *CreateOptions) error { return err } - fmt.Fprintf(stderr, "%s Initialized repository in './%s/'\n", greenCheck, path) + fmt.Fprintf(stderr, "%s Initialized repository in './%s/'\n", utils.GreenCheck(), path) } } return nil @@ -256,6 +257,7 @@ func createRun(opts *CreateOptions) error { fmt.Fprintln(opts.IO.Out, "Discarding...") return nil } + func interactiveRepoCreate(isDescEmpty bool, isVisibilityPassed bool, repoName string) (string, string, string, error) { qs := []*survey.Question{} @@ -284,7 +286,7 @@ func interactiveRepoCreate(isDescEmpty bool, isVisibilityPassed bool, repoName s Name: "repoVisibility", Prompt: &survey.Select{ Message: "Visibility", - Options: []string{"PUBLIC", "PRIVATE", "INTERNAL"}, + Options: []string{"Public", "Private", "Internal"}, }, } qs = append(qs, repoVisibilityQuestion) @@ -302,7 +304,7 @@ func interactiveRepoCreate(isDescEmpty bool, isVisibilityPassed bool, repoName s return "", "", "", err } - return answers.RepoOwner, answers.RepoDescription, answers.RepoVisibility, nil + return answers.RepoOwner, answers.RepoDescription, strings.ToUpper(answers.RepoVisibility), nil } @@ -311,15 +313,16 @@ func confirmSubmission(repoName string, repoOwner string, isConfirmFlagPassed *b promptString := "" if repoOwner != "" { - promptString = fmt.Sprintf("This will create %s/%s in your current directory. Continue? ", repoOwner, repoName) + promptString = fmt.Sprintf("This will create '%s/%s' in your current directory. Continue? ", repoOwner, repoName) } else { - promptString = fmt.Sprintf("This will create %s in your current directory. Continue? ", repoName) + promptString = fmt.Sprintf("This will create '%s' in your current directory. Continue? ", repoName) } confirmSubmitQuestion := &survey.Question{ Name: "confirmSubmit", Prompt: &survey.Confirm{ Message: promptString, + Default: true, }, } qs = append(qs, confirmSubmitQuestion)