-
Notifications
You must be signed in to change notification settings - Fork 117
Show copy progress for CopyFileToMachine on Shell Service #4918
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
Show copy progress for CopyFileToMachine on Shell Service #4918
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, see comments about newline + --no-progress
return pr.reader.Stat() | ||
} | ||
|
||
func (pr *progressReader) Close() error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider adding final \n
somewhere (potentially in Close)
as-is, the next shell prompt appears on the same line as the progress output
~/repo/rdk$ go run ./cli/viam machine part cp --part PART README.md machine:README.md
Copying README.md...
Progress: 100% (5577/5577 bytes)~/repo/rdk$
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops. Good catch. I had this but then I refactored to handle multiple files.
} | ||
uploadPercent := int(math.Ceil(100 * float64(bytes) / float64(fileSize))) | ||
//nolint:errcheck // progress display is non-critical | ||
_, _ = os.Stdout.WriteString(fmt.Sprintf("\rProgress: %d%% (%d/%d bytes)", uploadPercent, bytes, fileSize)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note this will work differently in headless shells
would not worry too much about it, but maybe add a --no-progress
field for reload
+ cp
, so that people can skip this behavior if it's messing with their shell?
(or assign this to me as afterwork so this PR can get merged; I feel bad that I took so long to start this review)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. Was easy.
Hey @cheukt can you give this a review? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good from SDK perspective, with one minor request!
cli/app.go
Outdated
@@ -75,6 +75,7 @@ const ( | |||
moduleFlagForce = "force" | |||
moduleFlagBinary = "binary" | |||
moduleFlagLocal = "local" | |||
moduleFlagNoProgress = "no-progress" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(minor) can we collapse this and cpFlagNoProgress
into a single flag (generalFlagNoProgress
or something like that)? Would prefer to not have two identical flags.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing! I did not see the general flags above earlier. Makes total sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
It was hard to see the progress of the two CLI operations that copy files to machines:
viam module reload
viam machine part cp
This PR adds wrappers around the CopyFileToMachine
NewCopyFileToMachineFactory
to print out the status of the file transfer.The
viam machine part cp
command now outputs this (works for both single and multiple files):And
viam module reload
: