Add the option to generate a README for the created repository#6264
Add the option to generate a README for the created repository#6264
Conversation
| 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) | ||
| } | ||
| } |
There was a problem hiding this comment.
@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:
- 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.
- Asserting that all defined prompts have been called. Here, I was using
switch..casestatements, 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!
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
Fixes #6233