Skip to content

Add the option to generate a README for the created repository#6264

Merged
mislav merged 2 commits intotrunkfrom
add-readme
Sep 21, 2022
Merged

Add the option to generate a README for the created repository#6264
mislav merged 2 commits intotrunkfrom
add-readme

Conversation

@mislav
Copy link
Contributor

@mislav mislav commented Sep 14, 2022

Fixes #6233

$ gh repo create --add-readme --private readme-test
✓ Created repository mislav/readme-test on GitHub
$ gh repo create
? What would you like to do? Create a new repository on GitHub from scratch
? Repository name readme-test
? Description
? Visibility Private
? Would you like to add a README file? Yes
? Would you like to add a .gitignore? No
? Would you like to add a license? No
? This will create "readme-test" as a private repository on GitHub. Continue? Yes
✓ Created repository mislav/readme-test on GitHub
? Clone the new repository locally? No

@mislav mislav requested a review from a team as a code owner September 14, 2022 17:11
@mislav mislav requested review from vilmibm and removed request for a team September 14, 2022 17:11
@mislav mislav mentioned this pull request Sep 15, 2022
23 tasks
Comment on lines +191 to +230
p.ConfirmFunc = func(message string, defaultValue bool) (bool, error) {
switch message {
case "Would you like to add a README file?":
return false, nil
case "Would you like to add a .gitignore?":
return true, nil
case "Would you like to add a license?":
return true, nil
case `This will create "REPO" as a private repository on GitHub. Continue?`:
return defaultValue, nil
case "Clone the new repository locally?":
return defaultValue, nil
default:
return false, fmt.Errorf("unexpected confirm prompt: %s", message)
}
}
p.InputFunc = func(message, defaultValue string) (string, error) {
switch message {
case "Repository name":
return "REPO", nil
case "Description":
return "my new repo", nil
default:
return "", fmt.Errorf("unexpected input prompt: %s", message)
}
}
p.SelectFunc = func(message, defaultValue string, options []string) (int, error) {
switch message {
case "What would you like to do?":
return prompter.IndexFor(options, "Create a new repository on GitHub from scratch")
case "Visibility":
return prompter.IndexFor(options, "Private")
case "Choose a license":
return prompter.IndexFor(options, "GNU Lesser General Public License v3.0")
case "Choose a .gitignore template":
return prompter.IndexFor(options, "Go")
default:
return 0, fmt.Errorf("unexpected select prompt: %s", message)
}
}
Copy link
Contributor Author

@mislav mislav Sep 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vilmibm Using the Prompter interface in the implementation has been a great success here, thank you!

Using the PrompterMock in tests has also significantly improved over the legacy AskStubber, especially with the help of handy functions like prompter.IndexFor(), but I was wondering whether you had some thoughts on the solutions for the following:

  1. Asserting the order of prompts as the user experiences them. Right now prompt stubs are grouped by type, as a result of defining ConfirmFunc, InputFunc, and SelectFunc sequentially.
  2. Asserting that all defined prompts have been called. Here, I was using switch..case statements, but I'm not sure how would I keep track of which ones were activated and assert that there are no "dead" ones.

None of these are hard requirements for me right now, but I was just wondering for the future. Thanks!

Copy link
Contributor

@vilmibm vilmibm Sep 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm open to both of these things (and figured we'd want something like them) but haven't yet put time into designing solutions.

Off the top of my head, maybe something like:

prompter.Register(pm.SelectFunc, "What account do you want to log out of?", func(_, _ string, opts []string) (int, error) {
  return prompter.IndexFor(opts, "github.com")
})

and a corresponding defer prompter.Verify(pm)

It won't be super pretty but I believe this approach can solve both of your considerations. If you like this idea I can work on it.

(I can also poke at a hack to get something like pm.Register to work instead of putting more stuff into the prompter package's top level)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for weighing in. Right now, I feel no pressing need for these features, so we can explore this when it's needed in the future.

@vilmibm vilmibm mentioned this pull request Sep 20, 2022
@mislav mislav merged commit 113acf9 into trunk Sep 21, 2022
@mislav mislav deleted the add-readme branch September 21, 2022 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add option to add README when creating a repo from scratch

2 participants