From 5cd977e3283041493a0031ec05cfae9eb82e27bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Tue, 14 Dec 2021 18:38:46 +0100 Subject: [PATCH] :nail_care: normalize prompt style for text inputs --- pkg/cmd/repo/create/create.go | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/pkg/cmd/repo/create/create.go b/pkg/cmd/repo/create/create.go index 1b840ca10..b8d8c764e 100644 --- a/pkg/cmd/repo/create/create.go +++ b/pkg/cmd/repo/create/create.go @@ -277,6 +277,10 @@ func createFromScratch(opts *CreateOptions) error { if err != nil { return err } + + if err := confirmSubmission(opts.Name, opts.Visibility); err != nil { + return err + } } if strings.Contains(opts.Name, "/") { @@ -329,16 +333,6 @@ func createFromScratch(opts *CreateOptions) error { templateRepoMainBranch = repo.DefaultBranchRef.Name } - if opts.Interactive { - doCreate, err := confirmSubmission(opts.Name, repoToCreate.RepoOwner(), opts.Visibility) - if err != nil { - return err - } - if !doCreate { - return cmdutil.CancelError - } - } - repo, err := repoCreate(httpClient, repoToCreate.RepoHost(), input) if err != nil { return err @@ -782,13 +776,13 @@ func interactiveRepoInfo(defaultName string) (string, string, string, error) { { Name: "repoName", Prompt: &survey.Input{ - Message: "Repository Name: ", + Message: "Repository name", Default: defaultName, }, }, { Name: "repoDescription", - Prompt: &survey.Input{Message: "Description: "}, + Prompt: &survey.Input{Message: "Description"}, }, { Name: "repoVisibility", @@ -815,7 +809,7 @@ func interactiveRepoInfo(defaultName string) (string, string, string, error) { func interactiveSource() (string, error) { var sourcePath string sourcePrompt := &survey.Input{ - Message: "Path to local repository: ", + Message: "Path to local repository", Default: "."} err := prompt.SurveyAskOne(sourcePrompt, &sourcePath) @@ -825,10 +819,10 @@ func interactiveSource() (string, error) { return sourcePath, nil } -func confirmSubmission(repoName, repoOwner, visibility string) (bool, error) { - targetRepo := normalizeRepoName(repoName) - if repoOwner != "" { - targetRepo = fmt.Sprintf("%s/%s", repoOwner, targetRepo) +func confirmSubmission(repoWithOwner, visibility string) error { + targetRepo := normalizeRepoName(repoWithOwner) + if idx := strings.IndexRune(repoWithOwner, '/'); idx > 0 { + targetRepo = repoWithOwner[0:idx+1] + normalizeRepoName(repoWithOwner[idx+1:]) } var answer struct { ConfirmSubmit bool @@ -841,9 +835,12 @@ func confirmSubmission(repoName, repoOwner, visibility string) (bool, error) { }, }}, &answer) if err != nil { - return false, err + return err } - return answer.ConfirmSubmit, nil + if !answer.ConfirmSubmit { + return cmdutil.CancelError + } + return nil } // normalizeRepoName takes in the repo name the user inputted and normalizes it using the same logic as GitHub (GitHub.com/new)