9061dd309f
Change-Id: If426c32219d32044d715ab6dfa9718807f32cb9f
49 lines
1.0 KiB
Go
49 lines
1.0 KiB
Go
// Copyright (C) 2021 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package main
|
|
|
|
import (
|
|
"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 clingy.Context) error {
|
|
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
|
|
}
|