storj/cmd/uplink/cmd_access_use.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

46 lines
897 B
Go

// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"context"
"fmt"
"github.com/zeebo/clingy"
"github.com/zeebo/errs"
"storj.io/storj/cmd/uplink/ulext"
)
type cmdAccessUse struct {
ex ulext.External
access string
}
func newCmdAccessUse(ex ulext.External) *cmdAccessUse {
return &cmdAccessUse{ex: ex}
}
func (c *cmdAccessUse) Setup(params clingy.Parameters) {
c.access = params.Arg("access", "Access name to use").(string)
}
func (c *cmdAccessUse) Execute(ctx context.Context) error {
_, accesses, err := c.ex.GetAccessInfo(true)
if err != nil {
return err
}
if _, ok := accesses[c.access]; !ok {
return errs.New("unknown access: %q", c.access)
}
if err := c.ex.SaveAccessInfo(c.access, accesses); err != nil {
return err
}
fmt.Fprintf(clingy.Stdout(ctx), "Switched default access to %q\n", c.access)
return nil
}