X Tutup
Skip to content

Commit 5cd977e

Browse files
committed
💅 normalize prompt style for text inputs
1 parent c90fc18 commit 5cd977e

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

pkg/cmd/repo/create/create.go

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,10 @@ func createFromScratch(opts *CreateOptions) error {
277277
if err != nil {
278278
return err
279279
}
280+
281+
if err := confirmSubmission(opts.Name, opts.Visibility); err != nil {
282+
return err
283+
}
280284
}
281285

282286
if strings.Contains(opts.Name, "/") {
@@ -329,16 +333,6 @@ func createFromScratch(opts *CreateOptions) error {
329333
templateRepoMainBranch = repo.DefaultBranchRef.Name
330334
}
331335

332-
if opts.Interactive {
333-
doCreate, err := confirmSubmission(opts.Name, repoToCreate.RepoOwner(), opts.Visibility)
334-
if err != nil {
335-
return err
336-
}
337-
if !doCreate {
338-
return cmdutil.CancelError
339-
}
340-
}
341-
342336
repo, err := repoCreate(httpClient, repoToCreate.RepoHost(), input)
343337
if err != nil {
344338
return err
@@ -782,13 +776,13 @@ func interactiveRepoInfo(defaultName string) (string, string, string, error) {
782776
{
783777
Name: "repoName",
784778
Prompt: &survey.Input{
785-
Message: "Repository Name: ",
779+
Message: "Repository name",
786780
Default: defaultName,
787781
},
788782
},
789783
{
790784
Name: "repoDescription",
791-
Prompt: &survey.Input{Message: "Description: "},
785+
Prompt: &survey.Input{Message: "Description"},
792786
},
793787
{
794788
Name: "repoVisibility",
@@ -815,7 +809,7 @@ func interactiveRepoInfo(defaultName string) (string, string, string, error) {
815809
func interactiveSource() (string, error) {
816810
var sourcePath string
817811
sourcePrompt := &survey.Input{
818-
Message: "Path to local repository: ",
812+
Message: "Path to local repository",
819813
Default: "."}
820814

821815
err := prompt.SurveyAskOne(sourcePrompt, &sourcePath)
@@ -825,10 +819,10 @@ func interactiveSource() (string, error) {
825819
return sourcePath, nil
826820
}
827821

828-
func confirmSubmission(repoName, repoOwner, visibility string) (bool, error) {
829-
targetRepo := normalizeRepoName(repoName)
830-
if repoOwner != "" {
831-
targetRepo = fmt.Sprintf("%s/%s", repoOwner, targetRepo)
822+
func confirmSubmission(repoWithOwner, visibility string) error {
823+
targetRepo := normalizeRepoName(repoWithOwner)
824+
if idx := strings.IndexRune(repoWithOwner, '/'); idx > 0 {
825+
targetRepo = repoWithOwner[0:idx+1] + normalizeRepoName(repoWithOwner[idx+1:])
832826
}
833827
var answer struct {
834828
ConfirmSubmit bool
@@ -841,9 +835,12 @@ func confirmSubmission(repoName, repoOwner, visibility string) (bool, error) {
841835
},
842836
}}, &answer)
843837
if err != nil {
844-
return false, err
838+
return err
839+
}
840+
if !answer.ConfirmSubmit {
841+
return cmdutil.CancelError
845842
}
846-
return answer.ConfirmSubmit, nil
843+
return nil
847844
}
848845

849846
// normalizeRepoName takes in the repo name the user inputted and normalizes it using the same logic as GitHub (GitHub.com/new)

0 commit comments

Comments
 (0)
X Tutup