59b8422318
this makes the distinction between an "access name" and an "access value" and talks about which is expected for commands. most are "access name or value". Change-Id: I43c0043a17d37e89ab5f87388ae9e890a8b59958
47 lines
919 B
Go
47 lines
919 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", "Serialized access value to save (prompted if unspecified)", "").(string)
|
|
|
|
params.Break()
|
|
c.am.Setup(params, c.ex, amSaveForced)
|
|
}
|
|
|
|
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)
|
|
}
|