Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add/improve spinner for build and deploy #322

Merged
merged 8 commits into from
May 3, 2021

Conversation

lance
Copy link
Member

@lance lance commented Apr 27, 2021

This commit modifies the progress meter so that, by default there is no
step counter. It also modifies the responsibility for calling Done(),
making it the job of the command rather than the client. This is because
the client does not know how many commands will be executed and therefore
cannot know when the progress bar is done.

Fixes: #296

Signed-off-by: Lance Ball lball@redhat.com

@lance lance requested a review from a team April 27, 2021 20:47
@lance lance self-assigned this Apr 27, 2021
@lance lance force-pushed the 296-spinner branch 2 times, most recently from 915b89b to 2d6802a Compare April 27, 2021 21:04
@lance lance marked this pull request as draft April 27, 2021 21:22
@lance lance marked this pull request as ready for review April 28, 2021 18:09
@lance lance changed the title feat: add spinner for build and improve for deploy feat: add/improve spinner for build and deploy Apr 28, 2021
This commit modifies the progress meter so that, by default there is no
step counter. It also modifies the responsibility for calling `Done()`,
making it the job of the command rather than the client. This is because
the client does not know how many commands will be executed and therefore
cannot know when the progress bar is done.

Fixes: knative#296

Signed-off-by: Lance Ball <lball@redhat.com>
lance added 2 commits April 28, 2021 16:09
Signed-off-by: Lance Ball <lball@redhat.com>
Signed-off-by: Lance Ball <lball@redhat.com>
Copy link
Member

@lkingland lkingland left a comment

Choose a reason for hiding this comment

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

Lookin good!

This commit adds String() to the progress bar, and moves logging
responsibility out of the deployer itself and fully into the client.
Deployer#Deploy() now returns a DeploymentResult.

Signed-off-by: Lance Ball <lball@redhat.com>
@lance
Copy link
Member Author

lance commented Apr 29, 2021

@lkingland thanks for your suggestions. I've incorporated them. PTAL

Signed-off-by: Lance Ball <lball@redhat.com>
@matejvasek
Copy link
Contributor

Why does this contains pkged.go? it seems that it packaged artifacts that we don't wan't to have there e.g. target for java templates.

lance added 2 commits April 29, 2021 16:46
Signed-off-by: Lance Ball <lball@redhat.com>
Signed-off-by: Lance Ball <lball@redhat.com>
@lance
Copy link
Member Author

lance commented Apr 29, 2021

Why does this contains pkged.go? it seems that it packaged artifacts that we don't wan't to have there e.g. target for java templates.

Hmm - it shouldn't have - and no longer does.

Copy link
Member

@lkingland lkingland left a comment

Choose a reason for hiding this comment

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

LGTM! I am sure this was tricky; fiddling with the line buffer is a descent into madness.

)

type DeploymentResult struct {
Status Status
Copy link
Member

@lkingland lkingland Apr 30, 2021

Choose a reason for hiding this comment

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

I also like this because it helps us maintain backwards compatibility

@@ -16,7 +16,7 @@ import (
servingv1 "knative.dev/serving/pkg/apis/serving/v1"
v1 "knative.dev/serving/pkg/apis/serving/v1"

bosonFunc "github.com/boson-project/func"
fn "github.com/boson-project/func"
Copy link
Member

Choose a reason for hiding this comment

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

certainly liking this import name better

// 5 Print linebreak such that subsequent messaes print correctly.
fmt.Fprintf(b.out, "\r%v%v%v%v/%v %v\n", up, clear, prefix, b.index, b.total, b.text)
// 5 Print linebreak such that subsequent messages print correctly.
fmt.Fprintf(b.out, "\r%v%v%v%v\n", up, clear, prefix, b)
Copy link
Member

Choose a reason for hiding this comment

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

Ah hah, handy use of b's .String already there.

Comment on lines 111 to 117
// Start the spinner if not already started
if b.ticker == nil {
fmt.Println()
b.ticker = time.NewTicker(100 * time.Millisecond)
go b.spin(b.ticker.C)
}

Copy link
Member

Choose a reason for hiding this comment

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

I see this is moved such that now the spiner is always running, even in verbose mode (but as a noop due to the verbosity check being moved to the spinner's write). I'm interested to know what bug this fixed, because fiddling with the line status is finnicky indeed, and of course it would be ideal to not start the goroutine if it's never going to be used.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes - it is absolutely fiddly messing with the line buffer! Oddly, with some of the other changes I made, the spinner ended up on the next line, e.g.

  Building function image
/        <- that's the spinner

Good point about not starting the goroutine if we don't have to. I'll fiddle with this a bit.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh and also - if we call overwrite() first, we end up overwriting the user command. When I type

$ # showing previous line for illustration
$ kn func build<enter>

We see this (you can see this with the current release binary).

$ # showing previous line for illustration
  Building function image
/        <- that's the spinner

Note that the kn func build command and the $ prompt are overwritten.

Signed-off-by: Lance Ball <lball@redhat.com>
Copy link
Member

@lkingland lkingland left a comment

Choose a reason for hiding this comment

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

I like it. It's friendly.

@lance lance merged commit 857b0fd into knative:main May 3, 2021
@lance lance deleted the 296-spinner branch May 3, 2021 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add spinner/progress bar to 'build' and 'deploy'
3 participants