-
Notifications
You must be signed in to change notification settings - Fork 11
/
piece.go
84 lines (79 loc) · 2.28 KB
/
piece.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
package dataprep
import (
"github.com/cockroachdb/errors"
"github.com/data-preservation-programs/singularity/cmd/cliutil"
"github.com/data-preservation-programs/singularity/database"
"github.com/data-preservation-programs/singularity/handler/dataprep"
"github.com/urfave/cli/v2"
)
var ListPiecesCmd = &cli.Command{
Name: "list-pieces",
Usage: "List all generated pieces for a preparation",
Category: "Piece Management",
ArgsUsage: "<preparation id|name>",
Before: cliutil.CheckNArgs,
Action: func(c *cli.Context) error {
db, closer, err := database.OpenFromCLI(c)
if err != nil {
return errors.WithStack(err)
}
defer closer.Close()
pieces, err := dataprep.Default.ListPiecesHandler(c.Context, db, c.Args().Get(0))
if err != nil {
return errors.WithStack(err)
}
cliutil.Print(c, pieces)
return nil
},
}
var AddPieceCmd = &cli.Command{
Name: "add-piece",
Usage: "Manually add piece info to a preparation. This is useful for pieces prepared by external tools.",
Category: "Piece Management",
ArgsUsage: "<preparation id|name>",
Before: cliutil.CheckNArgs,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "piece-cid",
Usage: "CID of the piece",
Required: true,
},
&cli.StringFlag{
Name: "piece-size",
Usage: "Size of the piece",
Required: true,
Value: "32GiB",
},
&cli.StringFlag{
Name: "file-path",
Usage: "Path to the CAR file, used to determine the size of the file and root CID",
},
&cli.StringFlag{
Name: "root-cid",
Usage: "Root CID of the CAR file",
},
&cli.Int64Flag{
Name: "file-size",
Usage: "Size of the CAR file, this is required for boost online deal. If not set, it will be determined from the file path if provided.",
},
},
Action: func(c *cli.Context) error {
db, closer, err := database.OpenFromCLI(c)
if err != nil {
return errors.WithStack(err)
}
defer closer.Close()
pieces, err := dataprep.Default.AddPieceHandler(c.Context, db, c.Args().Get(0), dataprep.AddPieceRequest{
PieceCID: c.String("piece-cid"),
PieceSize: c.String("piece-size"),
FilePath: c.String("file-path"),
RootCID: c.String("root-cid"),
FileSize: c.Int64("file-size"),
})
if err != nil {
return errors.WithStack(err)
}
cliutil.Print(c, pieces)
return nil
},
}