Skip to content

Commit cb7328d

Browse files
authored
buck: hide progress on windows (#481)
Signed-off-by: Sander Pick <sanderpick@gmail.com>
1 parent 2d6952e commit cb7328d

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

cmd/buck/cli/init.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ Use the '--hard' flag to discard all local changes.
7373
cmd.Fatal(errors.New("--cid cannot be used with an existing bucket"))
7474
}
7575

76-
unfreeze, err := c.Flags().GetBool("unfreeze")
77-
cmd.ErrCheck(err)
76+
// (jsign): re-enable when this feature is usable in mainnet.
77+
//unfreeze, err := c.Flags().GetBool("unfreeze")
78+
//cmd.ErrCheck(err)
79+
var unfreeze bool
7880
if unfreeze && xcid == cid.Undef {
7981
cmd.Fatal(errors.New("--unfreeze requires specifying --cid"))
8082
}

cmd/buck/cli/util.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cli
33
import (
44
"fmt"
55
"os"
6+
"runtime"
67

78
pb "github.com/cheggaaa/pb/v3"
89
"github.com/manifoldco/promptui"
@@ -31,19 +32,26 @@ func getConfirm(label string, auto bool) local.ConfirmDiffFunc {
3132
}
3233

3334
func handleEvents(events chan local.Event) {
34-
bar := pb.New(0)
35-
bar.Set(pb.Bytes, true)
36-
37-
tmp := `{{string . "prefix"}}{{counters . }} {{bar . "[" "=" ">" "-" "]"}} {{percent . }} {{etime . }}{{string . "suffix"}}`
38-
bar.SetTemplate(pb.ProgressBarTemplate(tmp))
35+
var bar *pb.ProgressBar
36+
if runtime.GOOS != "windows" {
37+
bar = pb.New(0)
38+
bar.Set(pb.Bytes, true)
39+
tmp := `{{string . "prefix"}}{{counters . }} {{bar . "[" "=" ">" "-" "]"}} {{percent . }} {{etime . }}{{string . "suffix"}}`
40+
bar.SetTemplate(pb.ProgressBarTemplate(tmp))
41+
}
3942

4043
clear := func() {
41-
_, _ = fmt.Fprintf(os.Stderr, "\033[2K\r")
44+
if bar != nil {
45+
_, _ = fmt.Fprintf(os.Stderr, "\033[2K\r")
46+
}
4247
}
4348

4449
for e := range events {
4550
switch e.Type {
4651
case local.EventProgress:
52+
if bar == nil {
53+
continue
54+
}
4755
bar.SetTotal(e.Size)
4856
bar.SetCurrent(e.Complete)
4957
if !bar.IsStarted() {
@@ -58,13 +66,13 @@ func handleEvents(events chan local.Event) {
5866
e.Path,
5967
formatBytes(e.Size, false),
6068
)
61-
if bar.IsStarted() {
69+
if bar != nil && bar.IsStarted() {
6270
bar.Write()
6371
}
6472
case local.EventFileRemoved:
6573
clear()
6674
_, _ = fmt.Fprintf(os.Stdout, "- %s\n", e.Path)
67-
if bar.IsStarted() {
75+
if bar != nil && bar.IsStarted() {
6876
bar.Write()
6977
}
7078
}

0 commit comments

Comments
 (0)