storj/cmd/uplinkng/cmd_access_save.go
Jeff Wendling e33f8d7170 cmd/uplinkng: access creation/restriction and review fixes
Change-Id: I649ae3615363685c28c39d1efb6a65fcad507f46
2021-08-11 02:29:49 +00:00

47 lines
900 B
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/uplinkng/ulext"
"storj.io/uplink"
)
type cmdAccessSave struct {
ex ulext.External
am accessMaker
access string
}
func newCmdAccessSave(ex ulext.External) *cmdAccessSave {
return &cmdAccessSave{ex: ex}
}
func (c *cmdAccessSave) Setup(params clingy.Parameters) {
c.access = params.Flag("access", "Access value to save (prompted if unspecified)", "").(string)
params.Break()
c.am.Setup(params, c.ex, true)
}
func (c *cmdAccessSave) Execute(ctx clingy.Context) (err error) {
if c.access == "" {
c.access, err = c.ex.PromptInput(ctx, "Access:")
if err != nil {
return errs.Wrap(err)
}
}
access, err := uplink.ParseAccess(c.access)
if err != nil {
return err
}
return c.am.Execute(ctx, access)
}