storj/cmd/uplink/cmd_mb.go
Márton Elek ea1408f7a8 go.mod: bump clingy dependency
As a reminder: latest clingy removed the requirement of having custom context (which made the usage of context.WithValue harder) and uses simple context instead.

Clingy saves the stdin/stdout/stderr to the context (earlier to separated context type) to make it available for unit testing.

Change-Id: I8896574f4670721de43a577cd4b35952e3b5d00e
2022-08-31 10:24:27 +00:00

51 lines
1.0 KiB
Go

// 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) 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
}