-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
cmd_simplefs_uploads.go
111 lines (97 loc) · 2.57 KB
/
cmd_simplefs_uploads.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright 2019 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
package client
import (
"context"
"sort"
"strings"
"time"
"github.com/keybase/cli"
"github.com/keybase/client/go/libcmdline"
"github.com/keybase/client/go/libkb"
keybase1 "github.com/keybase/client/go/protocol/keybase1"
)
// CmdSimpleFSUploads is the 'fs uploads' command.
type CmdSimpleFSUploads struct {
libkb.Contextified
filter keybase1.ListFilter
}
// NewCmdSimpleFSUploads creates a new cli.Command.
func NewCmdSimpleFSUploads(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
return cli.Command{
Name: "uploads",
Usage: "list current uploads",
Action: func(c *cli.Context) {
cl.ChooseCommand(&CmdSimpleFSUploads{
Contextified: libkb.NewContextified(g)}, "uploads", c)
cl.SetNoStandalone()
},
Flags: []cli.Flag{
cli.BoolFlag{
Name: "a, all",
Usage: "include entries starting with '.'",
},
},
}
}
func printUploads(
g *libkb.GlobalContext, filter keybase1.ListFilter, mustHavePrefix string) (
areUploads bool, err error) {
cli, err := GetSimpleFSClient(g)
if err != nil {
return false, err
}
status, err := cli.SimpleFSSyncStatus(context.TODO(), filter)
if err != nil {
return false, err
}
ui := g.UI.GetTerminalUI()
if len(status.SyncingPaths) == 0 && status.TotalSyncingBytes == 0 {
ui.Printf("There are currently no uploads in progress\n")
return false, nil
}
sort.Strings(status.SyncingPaths)
printed := false
for _, p := range status.SyncingPaths {
if !strings.HasPrefix(p, mustHavePrefix) {
continue
}
printed = true
ui.Printf("%s\n", p)
}
if printed {
ui.Printf("\n")
} else {
return false, nil
}
ui.Printf(
"%s left to upload\n", humanizeBytes(status.TotalSyncingBytes, false))
if status.EndEstimate != nil {
timeRemaining := time.Until(keybase1.FromTime(*status.EndEstimate))
ui.Printf("Estimated time remaining: %s\n",
timeRemaining.Round(1*time.Second))
}
return true, nil
}
// Run runs the command in client/server mode.
func (c *CmdSimpleFSUploads) Run() error {
_, err := printUploads(c.G(), c.filter, "")
return err
}
// ParseArgv gets the optional -a switch.
func (c *CmdSimpleFSUploads) ParseArgv(ctx *cli.Context) error {
if ctx.Bool("all") {
c.filter = keybase1.ListFilter_NO_FILTER
} else {
c.filter = keybase1.ListFilter_FILTER_ALL_HIDDEN
}
return nil
}
// GetUsage says what this command needs to operate.
func (c *CmdSimpleFSUploads) GetUsage() libkb.Usage {
return libkb.Usage{
Config: true,
KbKeyring: true,
API: true,
}
}