erikgeiser / promptkit

Go prompt library
MIT License
249 stars 21 forks source link

Selection example not up-to-date #14

Closed MarcBuch closed 1 year ago

MarcBuch commented 1 year ago

What?

The example code for the selection is not working anymore. selection.New() now takes a []*selection.Choice instead of the displayed []string.

Fix

I would suggest adjusting the selector example to:

choices := selection.Choices([]string{"Horse", "Car", "Plane", "Bike"})
sp := selection.New("What do you pick?", choices)

// ...

Thanks to you for creating this repo! It is very easy to use and opens the world for newbies to bubble tea. If needed, I can quickly create a PR.

erikgeiser commented 1 year ago

Hey, thanks for your feedback and sorry for the late reply. I'm not sure I understand you correctly, but as far as I can tell the examples are correct but you are using another version of the library locally. I'd like to give some context on the issue because it could be confusing for other people, too.

When I started writing the library I knew that a nice API for selection prompts would profit a lot from generics, but Go 1.18 was delayed, so I initially used the abstraction []*selection.Choices. However, I planned to change the API as soon as generics were available, that's also why I put a disclaimer in the README. Currently, the latest tagged version v0.7.0 still uses the abstraction.

The main branch, however, is already update to utilize generics. I'm guessing your problem is that go get github.com/erikgeiser/promptkit fetches the latest tagged version (v0.7.0 with []*selection.Choices) instead of the current state of the main branch, but when you look at the examples on Github, you already see the newer, untagged version with generics.

The reason I haven't tagged a new release yet is that I currently have little time and I want to help a few of the bigger projects that use promptkit to migrate by creating PRs because I want to avoid that they are put off by unexpected API changes. I haven't found the time to do that, yet.

The Fix:

If you are already using Go 1.18 or newer, you can use the latest, untagged version of promptkit with generics by specifying that you want to fetch the main branch like this:

go get github.com/erikgeiser/promptkit@main

If you are using an earlier Go version you can look at the examples at the snapshot of the currently tagged version v0.7.0 here:

https://github.com/erikgeiser/promptkit/tree/912fe7f8487dabfb392d159b9e5cb28a0f7e252e

I'm leaving this issue open so other people with the same problem can easily find it.

erikgeiser commented 1 year ago

I have now tagged and released a new version which fixes the mismatch between documentation and latest released version.