forked from irinazheltisheva/powergate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathffs_replace.go
More file actions
53 lines (44 loc) · 1.37 KB
/
ffs_replace.go
File metadata and controls
53 lines (44 loc) · 1.37 KB
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
package cmd
import (
"context"
"errors"
"time"
"github.com/caarlos0/spin"
"github.com/ipfs/go-cid"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
func init() {
ffsReplaceCmd.Flags().StringP("token", "t", "", "FFS access token")
ffsReplaceCmd.Flags().BoolP("watch", "w", false, "Watch the progress of the resulting job")
ffsCmd.AddCommand(ffsReplaceCmd)
}
var ffsReplaceCmd = &cobra.Command{
Use: "replace [cid1] [cid2]",
Short: "Pushes a StorageConfig for c2 equal to that of c1, and removes c1",
Long: `Pushes a StorageConfig for c2 equal to that of c1, and removes c1. This operation is more efficient than manually removing and adding in two separate operations`,
PreRun: func(cmd *cobra.Command, args []string) {
err := viper.BindPFlags(cmd.Flags())
checkErr(err)
},
Run: func(cmd *cobra.Command, args []string) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*60)
defer cancel()
if len(args) != 2 {
Fatal(errors.New("you must provide two cid arguments"))
}
c1, err := cid.Parse(args[0])
checkErr(err)
c2, err := cid.Parse(args[1])
checkErr(err)
s := spin.New("%s Replacing cid configuration...")
s.Start()
jid, err := fcClient.FFS.Replace(authCtx(ctx), c1, c2)
s.Stop()
checkErr(err)
Success("Replaced cid config with job id: %v", jid.String())
if viper.GetBool("watch") {
watchJobIds(jid)
}
},
}