-
Notifications
You must be signed in to change notification settings - Fork 402
/
cmd_mb.go
52 lines (39 loc) · 1.08 KB
/
cmd_mb.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
// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"context"
"github.com/zeebo/clingy"
"github.com/zeebo/errs"
"storj.io/storj/cmd/uplink/ulext"
"storj.io/storj/cmd/uplink/ulloc"
)
type cmdMb struct {
ex ulext.External
access string
name string
}
func newCmdMb(ex ulext.External) *cmdMb {
return &cmdMb{ex: ex}
}
func (c *cmdMb) Setup(params clingy.Parameters) {
c.access = params.Flag("access", "Access name or value to use", "").(string)
c.name = params.Arg("name", "Bucket name (sj://BUCKET)", clingy.Transform(ulloc.Parse),
clingy.Transform(func(location ulloc.Location) (string, error) {
if bucket, key, ok := location.RemoteParts(); key == "" && ok {
return bucket, nil
}
return "", errs.New("invalid bucket name")
}),
).(string)
}
func (c *cmdMb) Execute(ctx context.Context) (err error) {
defer mon.Task()(&ctx)(&err)
project, err := c.ex.OpenProject(ctx, c.access)
if err != nil {
return errs.Wrap(err)
}
defer func() { _ = project.Close() }()
_, err = project.CreateBucket(ctx, c.name)
return err
}