storj/cmd/uplink/cmd_access_use.go
Cameron 22261146be cmd/uplink: don't output stacktrace with unknown access
A stacktrace is unnecessary for this error, so don't print one.

https://github.com/storj/storj/issues/5910

Change-Id: Id9e5d9d188042cc7ac0dba571138d5f3e331a9d6
2023-09-20 10:06:47 +00:00

45 lines
938 B
Go

// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"context"
"fmt"
"github.com/zeebo/clingy"
"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 fmt.Errorf("ERROR: access %q does not exist. Use 'uplink access list' to see existing accesses", 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
}