codespace: use progress indicator#4556
Conversation
| if nameFilter == "" { | ||
| a.StartProgressIndicatorWithSuffix("Fetching codespaces") | ||
| codespaces, err = a.apiClient.ListCodespaces(ctx, -1) | ||
| a.StopProgressIndicator() |
There was a problem hiding this comment.
I wonder if there is a helper function one could write that would allow you to write this sequence each time you need a progress indicator:
progress.start()
defer progress.stop()
slowOperation()
Ideally it should work correctly even when the call sequence is start1 start2 stop2 stop1 so that you can use the above sequence of statements twice within a function that has two slow operations.
There was a problem hiding this comment.
I would need to test how two spinners would interact with each other. I did initially have something like this:
var repository *api.Repository
if err := a.perform("Fetching repository", func() error {
repository, err = a.apiClient.GetRepository(ctx, repo)
return err
}); err != nil {
return fmt.Errorf("error getting repository: %w", err)
}
But I didn't want to spread a.perform all over the place with vars everywhere. There's a tradeoff for sure.
There was a problem hiding this comment.
Yeah, we definitely don't want to go that route. Control flow abstraction is not one of Go's strengths.
I was imagining the helper would maintain an underlying spinner and a stack of unstopped starts, and would take care of calling underlying.stop in between two nested calls to outer.start; similarly, after a call to outer.stop, it would use underlying.start to restart the last unstopped task.
There was a problem hiding this comment.
I see... that sounds nice, having to manage the stop across possible error returns is tedious. Perhaps it's something we can consider for gh as a whole since the pattern I'm using here it's used heavily everywhere else. Likely not going to happen in this PR though 😄
This PR builds on top of #4555 and it changes the code to use IOStreams' progress indicator.
DEBUG=1has been set, then they are logged out to theio.OutgetOrChooseCodespacethat should probably also take a progressIndicator or an*App. I really wanted to move everything out ofpkg/cmd/codespaceandinternal/codespaces/app.goand other files. It feels like we need to this at some point. I actually did in another branch but the diff is huge 😬