status command: better handling of 'nothing to do' Complete state

This commit is contained in:
Christian Schwarz 2018-09-06 11:46:02 -07:00
parent c60ed78bc5
commit 1edf020ce7

View File

@ -211,9 +211,14 @@ func (t *tui) draw() {
t.newline() t.newline()
} }
maxFS, maxStatus := calculateMaxFilesystemAndVersionNameLength(all) var maxFSLen int
for _, fs := range all { for _, fs := range all {
printFilesystemStatus(fs, t, fs == rep.Active, maxFS, maxStatus) if len(fs.Filesystem) > maxFSLen {
maxFSLen = len(fs.Filesystem)
}
}
for _, fs := range all {
printFilesystemStatus(fs, t, fs == rep.Active, maxFSLen)
} }
} }
} }
@ -221,7 +226,7 @@ func (t *tui) draw() {
} }
const snapshotIndent = 1 const snapshotIndent = 1
func calculateMaxFilesystemAndVersionNameLength(all []*fsrep.Report) (maxFS, maxStatus int) { func calculateMaxFSLength(all []*fsrep.Report) (maxFS, maxStatus int) {
for _, e := range all { for _, e := range all {
if len(e.Filesystem) > maxFS { if len(e.Filesystem) > maxFS {
maxFS = len(e.Filesystem) maxFS = len(e.Filesystem)
@ -268,6 +273,8 @@ func (t *tui) drawBar(length int, bytes, totalBytes int64) {
if completedLength > length { if completedLength > length {
completedLength = length completedLength = length
} }
} else if totalBytes == bytes {
completedLength = length
} }
t.write("[") t.write("[")
@ -290,7 +297,7 @@ func StringStepState(s fsrep.StepState) string {
} }
} }
func filesystemStatusString(rep *fsrep.Report, active bool, maxFS, maxStatus int) (totalStatus string, bytes, totalBytes int64) { func filesystemStatusString(rep *fsrep.Report, active bool, fsWidth int) (line string, bytes, totalBytes int64) {
bytes = int64(0) bytes = int64(0)
totalBytes = int64(0) totalBytes = int64(0)
for _, s := range rep.Pending { for _, s := range rep.Pending {
@ -302,37 +309,35 @@ func filesystemStatusString(rep *fsrep.Report, active bool, maxFS, maxStatus int
totalBytes += s.ExpectedBytes totalBytes += s.ExpectedBytes
} }
nextStep := "" next := ""
if len(rep.Pending) > 0 { if rep.Problem != "" {
next = " problem: " + rep.Problem
} else if len(rep.Pending) > 0 {
if rep.Pending[0].From != "" { if rep.Pending[0].From != "" {
nextStep = fmt.Sprintf("%s => %s", rep.Pending[0].From, rep.Pending[0].To) next = fmt.Sprintf("next: %s => %s", rep.Pending[0].From, rep.Pending[0].To)
} else { } else {
nextStep = fmt.Sprintf("%s (full)", rep.Pending[0].To) next = fmt.Sprintf("next: %s (full)", rep.Pending[0].To)
} }
} }
status := fmt.Sprintf("%s (step %d/%d, %s/%s)", status := fmt.Sprintf("%s (step %d/%d, %s/%s)%s",
rep.Status, rep.Status,
len(rep.Completed), len(rep.Pending) + len(rep.Completed), len(rep.Completed), len(rep.Pending) + len(rep.Completed),
ByteCountBinary(bytes), ByteCountBinary(totalBytes), ByteCountBinary(bytes), ByteCountBinary(totalBytes),
next,
) )
if rep.Problem == "" && nextStep != "" {
status += fmt.Sprintf(" next: %s", nextStep)
} else if rep.Problem != "" {
status += fmt.Sprintf(" problem: %s", rep.Problem)
}
activeIndicator := " " activeIndicator := " "
if active { if active {
activeIndicator = "*" activeIndicator = "*"
} }
totalStatus = fmt.Sprintf("%s %s %s", line = fmt.Sprintf("%s %s %s",
activeIndicator, activeIndicator,
rightPad(rep.Filesystem, maxFS, " "), rightPad(rep.Filesystem, fsWidth, " "),
rightPad(status, maxStatus, " ")) status)
return totalStatus, bytes, totalBytes return line, bytes, totalBytes
} }
func printFilesystemStatus(rep *fsrep.Report, t *tui, active bool, maxFS, maxTotal int) { func printFilesystemStatus(rep *fsrep.Report, t *tui, active bool, maxFS int) {
totalStatus, _, _ := filesystemStatusString(rep, active, maxFS, maxTotal) totalStatus, _, _ := filesystemStatusString(rep, active, maxFS)
t.write(totalStatus) t.write(totalStatus)
t.newline() t.newline()
} }