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
This commit is contained in:
parent
47301e5718
commit
ea1408f7a8
@ -4,6 +4,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
@ -36,7 +37,7 @@ func (am *accessMaker) Setup(params clingy.Parameters, ex ulext.External) {
|
||||
).(bool)
|
||||
}
|
||||
|
||||
func (am *accessMaker) Execute(ctx clingy.Context, name string, access *uplink.Access) (_ *uplink.Access, err error) {
|
||||
func (am *accessMaker) Execute(ctx context.Context, name string, access *uplink.Access) (_ *uplink.Access, err error) {
|
||||
defaultName, accesses, err := am.ex.GetAccessInfo(false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -68,7 +69,7 @@ func (am *accessMaker) Execute(ctx clingy.Context, name string, access *uplink.A
|
||||
return nil, errs.Wrap(err)
|
||||
}
|
||||
|
||||
fmt.Fprintf(ctx, "Imported access %q to %q\n", name, am.ex.AccessInfoFile())
|
||||
fmt.Fprintf(clingy.Stdout(ctx), "Imported access %q to %q\n", name, am.ex.AccessInfoFile())
|
||||
}
|
||||
|
||||
return access, nil
|
||||
|
@ -4,6 +4,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"strconv"
|
||||
@ -45,7 +46,7 @@ func (c *cmdAccessCreate) Setup(params clingy.Parameters) {
|
||||
c.am.Setup(params, c.ex)
|
||||
}
|
||||
|
||||
func (c *cmdAccessCreate) Execute(ctx clingy.Context) (err error) {
|
||||
func (c *cmdAccessCreate) Execute(ctx context.Context) (err error) {
|
||||
if c.satelliteAddr == "" {
|
||||
if c.passphraseStdin {
|
||||
return errs.New("Must specify the satellite address as a flag when passphrase-stdin is set.")
|
||||
@ -68,7 +69,7 @@ func (c *cmdAccessCreate) Execute(ctx clingy.Context) (err error) {
|
||||
|
||||
var passphrase string
|
||||
if c.passphraseStdin {
|
||||
stdinData, err := ioutil.ReadAll(ctx.Stdin())
|
||||
stdinData, err := ioutil.ReadAll(clingy.Stdin(ctx))
|
||||
if err != nil {
|
||||
return errs.Wrap(err)
|
||||
}
|
||||
@ -106,7 +107,7 @@ func (c *cmdAccessCreate) Execute(ctx clingy.Context) (err error) {
|
||||
return errs.Wrap(err)
|
||||
}
|
||||
|
||||
fmt.Fprintln(ctx, serialized)
|
||||
fmt.Fprintln(clingy.Stdout(ctx), serialized)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -4,6 +4,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/zeebo/clingy"
|
||||
"github.com/zeebo/errs"
|
||||
|
||||
@ -26,7 +28,7 @@ func (c *cmdAccessExport) Setup(params clingy.Parameters) {
|
||||
c.filename = params.Arg("filename", "Name of the file to save to").(string)
|
||||
}
|
||||
|
||||
func (c *cmdAccessExport) Execute(ctx clingy.Context) error {
|
||||
func (c *cmdAccessExport) Execute(ctx context.Context) error {
|
||||
if c.filename == "" {
|
||||
return errs.New("Must specify a filename to write to.")
|
||||
}
|
||||
|
@ -4,6 +4,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/zeebo/clingy"
|
||||
"github.com/zeebo/errs"
|
||||
|
||||
@ -29,7 +31,7 @@ func (c *cmdAccessImport) Setup(params clingy.Parameters) {
|
||||
c.access = params.Arg("access|filename", "Serialized access value or file path to save").(string)
|
||||
}
|
||||
|
||||
func (c *cmdAccessImport) Execute(ctx clingy.Context) (err error) {
|
||||
func (c *cmdAccessImport) Execute(ctx context.Context) (err error) {
|
||||
if c.name == "" {
|
||||
return errs.New("Must specify a name to import the access as.")
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@ -37,7 +38,7 @@ func (c *cmdAccessInspect) Setup(params clingy.Parameters) {
|
||||
}
|
||||
|
||||
// Execute runs the command.
|
||||
func (c *cmdAccessInspect) Execute(ctx clingy.Context) error {
|
||||
func (c *cmdAccessInspect) Execute(ctx context.Context) error {
|
||||
toOpen := ""
|
||||
if c.access != nil {
|
||||
toOpen = *c.access
|
||||
@ -96,7 +97,7 @@ func (c *cmdAccessInspect) Execute(ctx clingy.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Fprintln(ctx, string(bs))
|
||||
fmt.Fprintln(clingy.Stdout(ctx), string(bs))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -31,7 +32,7 @@ func (c *cmdAccessList) Setup(params clingy.Parameters) {
|
||||
).(bool)
|
||||
}
|
||||
|
||||
func (c *cmdAccessList) Execute(ctx clingy.Context) error {
|
||||
func (c *cmdAccessList) Execute(ctx context.Context) error {
|
||||
defaultName, accesses, err := c.ex.GetAccessInfo(true)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -39,9 +40,9 @@ func (c *cmdAccessList) Execute(ctx clingy.Context) error {
|
||||
|
||||
var tw *tabbedWriter
|
||||
if c.verbose {
|
||||
tw = newTabbedWriter(ctx.Stdout(), "CURRENT", "NAME", "SATELLITE", "VALUE")
|
||||
tw = newTabbedWriter(clingy.Stdout(ctx), "CURRENT", "NAME", "SATELLITE", "VALUE")
|
||||
} else {
|
||||
tw = newTabbedWriter(ctx.Stdout(), "CURRENT", "NAME", "SATELLITE")
|
||||
tw = newTabbedWriter(clingy.Stdout(ctx), "CURRENT", "NAME", "SATELLITE")
|
||||
}
|
||||
defer tw.Done()
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/zeebo/clingy"
|
||||
@ -36,7 +37,7 @@ func (c *cmdAccessRegister) Setup(params clingy.Parameters) {
|
||||
c.accessNameOrValue = params.Arg("access", "The name or value of the access grant we're registering with the auth service", clingy.Optional).(*string)
|
||||
}
|
||||
|
||||
func (c *cmdAccessRegister) Execute(ctx clingy.Context) (err error) {
|
||||
func (c *cmdAccessRegister) Execute(ctx context.Context) (err error) {
|
||||
accessNameOrValue := ""
|
||||
if c.accessNameOrValue != nil && len(*c.accessNameOrValue) > 0 {
|
||||
accessNameOrValue = *c.accessNameOrValue
|
||||
|
@ -4,6 +4,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/zeebo/clingy"
|
||||
@ -26,7 +27,7 @@ func (c *cmdAccessRemove) Setup(params clingy.Parameters) {
|
||||
c.access = params.Arg("name", "Access name to delete").(string)
|
||||
}
|
||||
|
||||
func (c *cmdAccessRemove) Execute(ctx clingy.Context) error {
|
||||
func (c *cmdAccessRemove) Execute(ctx context.Context) error {
|
||||
defaultName, accesses, err := c.ex.GetAccessInfo(true)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -44,7 +45,7 @@ func (c *cmdAccessRemove) Execute(ctx clingy.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Fprintf(ctx, "Removed access %q from %q\n", c.access, c.ex.AccessInfoFile())
|
||||
fmt.Fprintf(clingy.Stdout(ctx), "Removed access %q from %q\n", c.access, c.ex.AccessInfoFile())
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/zeebo/clingy"
|
||||
@ -36,7 +37,7 @@ func (c *cmdAccessRestrict) Setup(params clingy.Parameters) {
|
||||
c.am.perms.Setup(params, true)
|
||||
}
|
||||
|
||||
func (c *cmdAccessRestrict) Execute(ctx clingy.Context) error {
|
||||
func (c *cmdAccessRestrict) Execute(ctx context.Context) error {
|
||||
access, err := c.ex.OpenAccess(c.access)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -56,6 +57,6 @@ func (c *cmdAccessRestrict) Execute(ctx clingy.Context) error {
|
||||
return errs.Wrap(err)
|
||||
}
|
||||
|
||||
fmt.Fprintln(ctx, serialized)
|
||||
fmt.Fprintln(clingy.Stdout(ctx), serialized)
|
||||
return nil
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/zeebo/clingy"
|
||||
@ -27,7 +28,7 @@ func (c *cmdAccessRevoke) Setup(params clingy.Parameters) {
|
||||
c.revokee = params.Arg("revokee", "Access name or value revoke").(string)
|
||||
}
|
||||
|
||||
func (c *cmdAccessRevoke) Execute(ctx clingy.Context) error {
|
||||
func (c *cmdAccessRevoke) Execute(ctx context.Context) error {
|
||||
project, err := c.ex.OpenProject(ctx, c.access)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -43,7 +44,7 @@ func (c *cmdAccessRevoke) Execute(ctx clingy.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Fprintf(ctx, "Revoked access %q\n", c.revokee)
|
||||
fmt.Fprintf(clingy.Stdout(ctx), "Revoked access %q\n", c.revokee)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
@ -37,7 +38,7 @@ func (c *cmdAccessSetup) Setup(params clingy.Parameters) {
|
||||
c.am.Setup(params, c.ex)
|
||||
}
|
||||
|
||||
func (c *cmdAccessSetup) Execute(ctx clingy.Context) (err error) {
|
||||
func (c *cmdAccessSetup) Execute(ctx context.Context) (err error) {
|
||||
name, err := c.ex.PromptInput(ctx, "Enter name to import as [default: main]:")
|
||||
if err != nil {
|
||||
return errs.Wrap(err)
|
||||
@ -88,7 +89,7 @@ func (c *cmdAccessSetup) Execute(ctx clingy.Context) (err error) {
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Fprintf(ctx, "Switched default access to %q\n", name)
|
||||
fmt.Fprintf(clingy.Stdout(ctx), "Switched default access to %q\n", name)
|
||||
|
||||
answer, err := c.ex.PromptInput(ctx, "Would you like S3 backwards-compatible Gateway credentials? (y/N):")
|
||||
if err != nil {
|
||||
|
@ -4,6 +4,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/zeebo/clingy"
|
||||
@ -26,7 +27,7 @@ func (c *cmdAccessUse) Setup(params clingy.Parameters) {
|
||||
c.access = params.Arg("access", "Access name to use").(string)
|
||||
}
|
||||
|
||||
func (c *cmdAccessUse) Execute(ctx clingy.Context) error {
|
||||
func (c *cmdAccessUse) Execute(ctx context.Context) error {
|
||||
_, accesses, err := c.ex.GetAccessInfo(true)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -38,7 +39,7 @@ func (c *cmdAccessUse) Execute(ctx clingy.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Fprintf(ctx, "Switched default access to %q\n", c.access)
|
||||
fmt.Fprintf(clingy.Stdout(ctx), "Switched default access to %q\n", c.access)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ func (c *cmdCp) Setup(params clingy.Parameters) {
|
||||
c.dest = params.Arg("dest", "Destination to copy, use - for standard output", clingy.Transform(ulloc.Parse)).(ulloc.Location)
|
||||
}
|
||||
|
||||
func (c *cmdCp) Execute(ctx clingy.Context) error {
|
||||
func (c *cmdCp) Execute(ctx context.Context) error {
|
||||
fs, err := c.ex.OpenFilesystem(ctx, c.access, ulext.ConnectionPoolOptions(rpcpool.Options{
|
||||
Capacity: 100 * c.parallelism,
|
||||
KeyCapacity: 5,
|
||||
@ -150,13 +150,13 @@ func (c *cmdCp) Execute(ctx clingy.Context) error {
|
||||
c.dest = joinDestWith(c.dest, base)
|
||||
|
||||
if !c.source.Std() && !c.dest.Std() {
|
||||
fmt.Fprintln(ctx.Stdout(), copyVerb(c.source, c.dest), c.source, "to", c.dest)
|
||||
fmt.Fprintln(clingy.Stdout(ctx), copyVerb(c.source, c.dest), c.source, "to", c.dest)
|
||||
}
|
||||
|
||||
return c.copyFile(ctx, fs, c.source, c.dest, c.progress)
|
||||
}
|
||||
|
||||
func (c *cmdCp) copyRecursive(ctx clingy.Context, fs ulfs.Filesystem) error {
|
||||
func (c *cmdCp) copyRecursive(ctx context.Context, fs ulfs.Filesystem) error {
|
||||
if c.source.Std() || c.dest.Std() {
|
||||
return errs.New("cannot recursively copy to stdin/stdout")
|
||||
}
|
||||
@ -201,10 +201,10 @@ func (c *cmdCp) copyRecursive(ctx clingy.Context, fs ulfs.Filesystem) error {
|
||||
dest := joinDestWith(c.dest, rel)
|
||||
|
||||
ok := limiter.Go(ctx, func() {
|
||||
fprintln(ctx.Stdout(), copyVerb(source, dest), source, "to", dest)
|
||||
fprintln(clingy.Stdout(ctx), copyVerb(source, dest), source, "to", dest)
|
||||
|
||||
if err := c.copyFile(ctx, fs, source, dest, false); err != nil {
|
||||
fprintln(ctx.Stderr(), copyVerb(source, dest), "failed:", err.Error())
|
||||
fprintln(clingy.Stdout(ctx), copyVerb(source, dest), "failed:", err.Error())
|
||||
addError(err)
|
||||
}
|
||||
})
|
||||
@ -223,7 +223,7 @@ func (c *cmdCp) copyRecursive(ctx clingy.Context, fs ulfs.Filesystem) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *cmdCp) copyFile(ctx clingy.Context, fs ulfs.Filesystem, source, dest ulloc.Location, progress bool) error {
|
||||
func (c *cmdCp) copyFile(ctx context.Context, fs ulfs.Filesystem, source, dest ulloc.Location, progress bool) error {
|
||||
if c.dryrun {
|
||||
return nil
|
||||
}
|
||||
@ -254,7 +254,7 @@ func (c *cmdCp) copyFile(ctx clingy.Context, fs ulfs.Filesystem, source, dest ul
|
||||
|
||||
var bar *progressbar.ProgressBar
|
||||
if progress && !c.dest.Std() {
|
||||
bar = progressbar.New64(0).SetWriter(ctx.Stdout())
|
||||
bar = progressbar.New64(0).SetWriter(clingy.Stdout(ctx))
|
||||
defer bar.Finish()
|
||||
}
|
||||
|
||||
@ -313,7 +313,7 @@ func joinDestWith(dest ulloc.Location, suffix string) ulloc.Location {
|
||||
}
|
||||
|
||||
func (c *cmdCp) parallelCopy(
|
||||
clctx clingy.Context,
|
||||
clctx context.Context,
|
||||
dst ulfs.MultiWriteHandle,
|
||||
src ulfs.MultiReadHandle,
|
||||
p int, chunkSize int64,
|
||||
|
@ -4,6 +4,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
"time"
|
||||
@ -63,14 +64,14 @@ func (c *cmdLs) Setup(params clingy.Parameters) {
|
||||
).(*ulloc.Location)
|
||||
}
|
||||
|
||||
func (c *cmdLs) Execute(ctx clingy.Context) error {
|
||||
func (c *cmdLs) Execute(ctx context.Context) error {
|
||||
if c.prefix == nil {
|
||||
return c.listBuckets(ctx)
|
||||
}
|
||||
return c.listLocation(ctx, *c.prefix)
|
||||
}
|
||||
|
||||
func (c *cmdLs) listBuckets(ctx clingy.Context) error {
|
||||
func (c *cmdLs) listBuckets(ctx context.Context) error {
|
||||
project, err := c.ex.OpenProject(ctx, c.access)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -89,7 +90,7 @@ func (c *cmdLs) listBuckets(ctx clingy.Context) error {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *cmdLs) listLocation(ctx clingy.Context, prefix ulloc.Location) error {
|
||||
func (c *cmdLs) listLocation(ctx context.Context, prefix ulloc.Location) error {
|
||||
fs, err := c.ex.OpenFilesystem(ctx, c.access, ulext.BypassEncryption(c.encrypted))
|
||||
if err != nil {
|
||||
return err
|
||||
@ -120,8 +121,8 @@ func (c *cmdLs) listLocation(ctx clingy.Context, prefix ulloc.Location) error {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *cmdLs) printTabbedBucket(ctx clingy.Context, iter *uplink.BucketIterator) (err error) {
|
||||
tw := newTabbedWriter(ctx.Stdout(), "CREATED", "NAME")
|
||||
func (c *cmdLs) printTabbedBucket(ctx context.Context, iter *uplink.BucketIterator) (err error) {
|
||||
tw := newTabbedWriter(clingy.Stdout(ctx), "CREATED", "NAME")
|
||||
defer tw.Done()
|
||||
|
||||
for iter.Next() {
|
||||
@ -131,8 +132,8 @@ func (c *cmdLs) printTabbedBucket(ctx clingy.Context, iter *uplink.BucketIterato
|
||||
return iter.Err()
|
||||
}
|
||||
|
||||
func (c *cmdLs) printJSONBucket(ctx clingy.Context, iter *uplink.BucketIterator) (err error) {
|
||||
jw := json.NewEncoder(ctx.Stdout())
|
||||
func (c *cmdLs) printJSONBucket(ctx context.Context, iter *uplink.BucketIterator) (err error) {
|
||||
jw := json.NewEncoder(clingy.Stdout(ctx))
|
||||
|
||||
for iter.Next() {
|
||||
obj := iter.Item()
|
||||
@ -145,13 +146,13 @@ func (c *cmdLs) printJSONBucket(ctx clingy.Context, iter *uplink.BucketIterator)
|
||||
return iter.Err()
|
||||
}
|
||||
|
||||
func (c *cmdLs) printTabbedLocation(ctx clingy.Context, iter ulfs.ObjectIterator) (err error) {
|
||||
func (c *cmdLs) printTabbedLocation(ctx context.Context, iter ulfs.ObjectIterator) (err error) {
|
||||
headers := []string{"KIND", "CREATED", "SIZE", "KEY"}
|
||||
if c.expanded {
|
||||
headers = append(headers, "EXPIRES", "META")
|
||||
}
|
||||
|
||||
tw := newTabbedWriter(ctx.Stdout(), headers...)
|
||||
tw := newTabbedWriter(clingy.Stdout(ctx), headers...)
|
||||
defer tw.Done()
|
||||
|
||||
// iterate and print the results
|
||||
@ -176,8 +177,8 @@ func (c *cmdLs) printTabbedLocation(ctx clingy.Context, iter ulfs.ObjectIterator
|
||||
return iter.Err()
|
||||
}
|
||||
|
||||
func (c *cmdLs) printJSONLocation(ctx clingy.Context, iter ulfs.ObjectIterator) (err error) {
|
||||
jw := json.NewEncoder(ctx.Stdout())
|
||||
func (c *cmdLs) printJSONLocation(ctx context.Context, iter ulfs.ObjectIterator) (err error) {
|
||||
jw := json.NewEncoder(clingy.Stdout(ctx))
|
||||
|
||||
for iter.Next() {
|
||||
obj := iter.Item()
|
||||
|
@ -4,6 +4,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/zeebo/clingy"
|
||||
"github.com/zeebo/errs"
|
||||
|
||||
@ -36,7 +38,7 @@ func (c *cmdMb) Setup(params clingy.Parameters) {
|
||||
).(string)
|
||||
}
|
||||
|
||||
func (c *cmdMb) Execute(ctx clingy.Context) error {
|
||||
func (c *cmdMb) Execute(ctx context.Context) error {
|
||||
project, err := c.ex.OpenProject(ctx, c.access)
|
||||
if err != nil {
|
||||
return errs.Wrap(err)
|
||||
|
@ -4,6 +4,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
@ -41,7 +42,7 @@ func (c *cmdMetaGet) Setup(params clingy.Parameters) {
|
||||
c.entry = params.Arg("entry", "Metadata entry to get", clingy.Optional).(*string)
|
||||
}
|
||||
|
||||
func (c *cmdMetaGet) Execute(ctx clingy.Context) error {
|
||||
func (c *cmdMetaGet) Execute(ctx context.Context) error {
|
||||
project, err := c.ex.OpenProject(ctx, c.access, ulext.BypassEncryption(c.encrypted))
|
||||
if err != nil {
|
||||
return err
|
||||
@ -64,12 +65,12 @@ func (c *cmdMetaGet) Execute(ctx clingy.Context) error {
|
||||
return errs.New("entry %q does not exist", *c.entry)
|
||||
}
|
||||
|
||||
fmt.Fprintln(ctx.Stdout(), value)
|
||||
fmt.Fprintln(clingy.Stdout(ctx), value)
|
||||
return nil
|
||||
}
|
||||
|
||||
if object.Custom == nil {
|
||||
fmt.Fprintln(ctx.Stdout(), "{}")
|
||||
fmt.Fprintln(clingy.Stdout(ctx), "{}")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -78,6 +79,6 @@ func (c *cmdMetaGet) Execute(ctx clingy.Context) error {
|
||||
return errs.Wrap(err)
|
||||
}
|
||||
|
||||
fmt.Fprintln(ctx.Stdout(), string(data))
|
||||
fmt.Fprintln(clingy.Stdout(ctx), string(data))
|
||||
return nil
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
@ -62,7 +63,7 @@ func (c *cmdMv) Setup(params clingy.Parameters) {
|
||||
c.dest = params.Arg("dest", "Destination to move", clingy.Transform(ulloc.Parse)).(ulloc.Location)
|
||||
}
|
||||
|
||||
func (c *cmdMv) Execute(ctx clingy.Context) error {
|
||||
func (c *cmdMv) Execute(ctx context.Context) error {
|
||||
fs, err := c.ex.OpenFilesystem(ctx, c.access)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -113,7 +114,7 @@ func (c *cmdMv) Execute(ctx clingy.Context) error {
|
||||
return c.moveFile(ctx, fs, c.source, c.dest)
|
||||
}
|
||||
|
||||
func (c *cmdMv) moveRecursive(ctx clingy.Context, fs ulfs.Filesystem) error {
|
||||
func (c *cmdMv) moveRecursive(ctx context.Context, fs ulfs.Filesystem) error {
|
||||
iter, err := fs.List(ctx, c.source, &ulfs.ListOptions{
|
||||
Recursive: true,
|
||||
})
|
||||
@ -166,11 +167,11 @@ func (c *cmdMv) moveRecursive(ctx clingy.Context, fs ulfs.Filesystem) error {
|
||||
|
||||
ok := limiter.Go(ctx, func() {
|
||||
if c.progress {
|
||||
fprintln(ctx.Stdout(), "Move", source, "to", dest)
|
||||
fprintln(clingy.Stdout(ctx), "Move", source, "to", dest)
|
||||
}
|
||||
|
||||
if err := c.moveFile(ctx, fs, source, dest); err != nil {
|
||||
fprintln(ctx.Stderr(), "Move", "failed:", err.Error())
|
||||
fprintln(clingy.Stdout(ctx), "Move", "failed:", err.Error())
|
||||
addError(err)
|
||||
}
|
||||
})
|
||||
@ -187,7 +188,7 @@ func (c *cmdMv) moveRecursive(ctx clingy.Context, fs ulfs.Filesystem) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *cmdMv) moveFile(ctx clingy.Context, fs ulfs.Filesystem, source, dest ulloc.Location) error {
|
||||
func (c *cmdMv) moveFile(ctx context.Context, fs ulfs.Filesystem, source, dest ulloc.Location) error {
|
||||
if c.dryrun {
|
||||
return nil
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
@ -38,7 +39,7 @@ func (c *cmdRb) Setup(params clingy.Parameters) {
|
||||
).(ulloc.Location)
|
||||
}
|
||||
|
||||
func (c *cmdRb) Execute(ctx clingy.Context) error {
|
||||
func (c *cmdRb) Execute(ctx context.Context) error {
|
||||
project, err := c.ex.OpenProject(ctx, c.access)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -62,6 +63,6 @@ func (c *cmdRb) Execute(ctx clingy.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Fprintf(ctx.Stdout(), "Bucket %q has been deleted.\n", bucket)
|
||||
fmt.Fprintf(clingy.Stdout(ctx), "Bucket %q has been deleted.\n", bucket)
|
||||
return nil
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
@ -62,7 +63,7 @@ func (c *cmdRm) Setup(params clingy.Parameters) {
|
||||
).(ulloc.Location)
|
||||
}
|
||||
|
||||
func (c *cmdRm) Execute(ctx clingy.Context) error {
|
||||
func (c *cmdRm) Execute(ctx context.Context) error {
|
||||
if c.location.Local() {
|
||||
return errs.New("remove %v skipped: local delete", c.location)
|
||||
}
|
||||
@ -81,7 +82,7 @@ func (c *cmdRm) Execute(ctx clingy.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Fprintln(ctx.Stdout(), "removed", c.location)
|
||||
fmt.Fprintln(clingy.Stdout(ctx), "removed", c.location)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -121,10 +122,10 @@ func (c *cmdRm) Execute(ctx clingy.Context) error {
|
||||
Pending: c.pending,
|
||||
})
|
||||
if err != nil {
|
||||
fprintln(ctx.Stderr(), "remove", loc, "failed:", err.Error())
|
||||
fprintln(clingy.Stderr(ctx), "remove", loc, "failed:", err.Error())
|
||||
addError(err)
|
||||
} else {
|
||||
fprintln(ctx.Stdout(), "removed", loc)
|
||||
fprintln(clingy.Stdout(ctx), "removed", loc)
|
||||
}
|
||||
})
|
||||
if !ok {
|
||||
|
@ -63,7 +63,7 @@ func (c *cmdShare) Setup(params clingy.Parameters) {
|
||||
c.ap.Setup(params, false)
|
||||
}
|
||||
|
||||
func (c *cmdShare) Execute(ctx clingy.Context) error {
|
||||
func (c *cmdShare) Execute(ctx context.Context) error {
|
||||
if len(c.ap.prefixes) == 0 {
|
||||
return errs.New("You must specify at least one prefix to share. Use the access restrict command to restrict with no prefixes.")
|
||||
}
|
||||
@ -84,8 +84,8 @@ func (c *cmdShare) Execute(ctx clingy.Context) error {
|
||||
c.register = true
|
||||
|
||||
if c.ap.notAfter.String() == "" {
|
||||
fmt.Fprintf(ctx, "It's not recommended to create a shared Access without an expiration date.")
|
||||
fmt.Fprintf(ctx, "If you wish to do so anyway, please run this command with --not-after=none.")
|
||||
fmt.Fprintf(clingy.Stdout(ctx), "It's not recommended to create a shared Access without an expiration date.")
|
||||
fmt.Fprintf(clingy.Stdout(ctx), "If you wish to do so anyway, please run this command with --not-after=none.")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -99,17 +99,17 @@ func (c *cmdShare) Execute(ctx clingy.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Fprintf(ctx, "Sharing access to satellite %s\n", access.SatelliteAddress())
|
||||
fmt.Fprintf(ctx, "=========== ACCESS RESTRICTIONS ==========================================================\n")
|
||||
fmt.Fprintf(ctx, "Download : %s\n", formatPermission(c.ap.AllowDownload()))
|
||||
fmt.Fprintf(ctx, "Upload : %s\n", formatPermission(c.ap.AllowUpload()))
|
||||
fmt.Fprintf(ctx, "Lists : %s\n", formatPermission(c.ap.AllowList()))
|
||||
fmt.Fprintf(ctx, "Deletes : %s\n", formatPermission(c.ap.AllowDelete()))
|
||||
fmt.Fprintf(ctx, "NotBefore : %s\n", formatTimeRestriction(c.ap.notBefore))
|
||||
fmt.Fprintf(ctx, "NotAfter : %s\n", formatTimeRestriction(c.ap.notAfter))
|
||||
fmt.Fprintf(ctx, "Paths : %s\n", formatPaths(c.ap.prefixes))
|
||||
fmt.Fprintf(ctx, "=========== SERIALIZED ACCESS WITH THE ABOVE RESTRICTIONS TO SHARE WITH OTHERS ===========\n")
|
||||
fmt.Fprintf(ctx, "Access : %s\n", newAccessData)
|
||||
fmt.Fprintf(clingy.Stdout(ctx), "Sharing access to satellite %s\n", access.SatelliteAddress())
|
||||
fmt.Fprintf(clingy.Stdout(ctx), "=========== ACCESS RESTRICTIONS ==========================================================\n")
|
||||
fmt.Fprintf(clingy.Stdout(ctx), "Download : %s\n", formatPermission(c.ap.AllowDownload()))
|
||||
fmt.Fprintf(clingy.Stdout(ctx), "Upload : %s\n", formatPermission(c.ap.AllowUpload()))
|
||||
fmt.Fprintf(clingy.Stdout(ctx), "Lists : %s\n", formatPermission(c.ap.AllowList()))
|
||||
fmt.Fprintf(clingy.Stdout(ctx), "Deletes : %s\n", formatPermission(c.ap.AllowDelete()))
|
||||
fmt.Fprintf(clingy.Stdout(ctx), "NotBefore : %s\n", formatTimeRestriction(c.ap.notBefore))
|
||||
fmt.Fprintf(clingy.Stdout(ctx), "NotAfter : %s\n", formatTimeRestriction(c.ap.notAfter))
|
||||
fmt.Fprintf(clingy.Stdout(ctx), "Paths : %s\n", formatPaths(c.ap.prefixes))
|
||||
fmt.Fprintf(clingy.Stdout(ctx), "=========== SERIALIZED ACCESS WITH THE ABOVE RESTRICTIONS TO SHARE WITH OTHERS ===========\n")
|
||||
fmt.Fprintf(clingy.Stdout(ctx), "Access : %s\n", newAccessData)
|
||||
|
||||
if c.register {
|
||||
credentials, err := RegisterAccess(ctx, access, c.authService, c.public, c.caCert)
|
||||
@ -120,7 +120,7 @@ func (c *cmdShare) Execute(ctx clingy.Context) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = fmt.Fprintln(ctx, "Public Access: ", c.public)
|
||||
_, err = fmt.Fprintln(clingy.Stdout(ctx), "Public Access: ", c.public)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -157,7 +157,7 @@ func (c *cmdShare) Execute(ctx clingy.Context) error {
|
||||
if err := ioutil.WriteFile(exportTo, []byte(newAccessData+"\n"), 0600); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Fprintln(ctx, "Exported to:", exportTo)
|
||||
fmt.Fprintln(clingy.Stdout(ctx), "Exported to:", exportTo)
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -226,7 +226,7 @@ func RegisterAccess(ctx context.Context, access *uplink.Access, authService stri
|
||||
}
|
||||
|
||||
// Creates linksharing url for allowed path prefixes.
|
||||
func createURL(ctx clingy.Context, accessKeyID string, prefixes []uplink.SharePrefix, baseURL string) (err error) {
|
||||
func createURL(ctx context.Context, accessKeyID string, prefixes []uplink.SharePrefix, baseURL string) (err error) {
|
||||
if len(prefixes) == 0 {
|
||||
return errs.New("need at least a bucket to create a working linkshare URL")
|
||||
}
|
||||
@ -239,16 +239,16 @@ func createURL(ctx clingy.Context, accessKeyID string, prefixes []uplink.SharePr
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Fprintf(ctx, "=========== BROWSER URL ==================================================================\n")
|
||||
fmt.Fprintf(clingy.Stdout(ctx), "=========== BROWSER URL ==================================================================\n")
|
||||
if key != "" && key[len(key)-1:] != "/" {
|
||||
fmt.Fprintf(ctx, "REMINDER : Object key must end in '/' when trying to share a prefix\n")
|
||||
fmt.Fprintf(clingy.Stdout(ctx), "REMINDER : Object key must end in '/' when trying to share a prefix\n")
|
||||
}
|
||||
fmt.Fprintf(ctx, "URL : %s\n", url)
|
||||
fmt.Fprintf(clingy.Stdout(ctx), "URL : %s\n", url)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Creates dns record info for allowed path prefixes.
|
||||
func createDNS(ctx clingy.Context, accessKey string, prefixes []uplink.SharePrefix, baseURL, dns string) (err error) {
|
||||
func createDNS(ctx context.Context, accessKey string, prefixes []uplink.SharePrefix, baseURL, dns string) (err error) {
|
||||
if len(prefixes) == 0 {
|
||||
return errs.New("need at least a bucket to create DNS records")
|
||||
}
|
||||
@ -268,23 +268,23 @@ func createDNS(ctx clingy.Context, accessKey string, prefixes []uplink.SharePref
|
||||
printStorjRoot = fmt.Sprintf("txt-%s\tIN\tTXT \tstorj-root:%s/%s", dns, bucket, key)
|
||||
}
|
||||
|
||||
fmt.Fprintf(ctx, "=========== DNS INFO =====================================================================\n")
|
||||
fmt.Fprintf(ctx, "Remember to update the $ORIGIN with your domain name. You may also change the $TTL.\n")
|
||||
fmt.Fprintf(ctx, "$ORIGIN example.com.\n")
|
||||
fmt.Fprintf(ctx, "$TTL 3600\n")
|
||||
fmt.Fprintf(ctx, "%s \tIN\tCNAME\t%s.\n", dns, CNAME.Host)
|
||||
fmt.Fprintln(ctx, printStorjRoot)
|
||||
fmt.Fprintf(ctx, "txt-%s\tIN\tTXT \tstorj-access:%s\n", dns, accessKey)
|
||||
fmt.Fprintf(clingy.Stdout(ctx), "=========== DNS INFO =====================================================================\n")
|
||||
fmt.Fprintf(clingy.Stdout(ctx), "Remember to update the $ORIGIN with your domain name. You may also change the $TTL.\n")
|
||||
fmt.Fprintf(clingy.Stdout(ctx), "$ORIGIN example.com.\n")
|
||||
fmt.Fprintf(clingy.Stdout(ctx), "$TTL 3600\n")
|
||||
fmt.Fprintf(clingy.Stdout(ctx), "%s \tIN\tCNAME\t%s.\n", dns, CNAME.Host)
|
||||
fmt.Fprintln(clingy.Stdout(ctx), printStorjRoot)
|
||||
fmt.Fprintf(clingy.Stdout(ctx), "txt-%s\tIN\tTXT \tstorj-access:%s\n", dns, accessKey)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// DisplayGatewayCredentials formats and writes credentials to stdout.
|
||||
func DisplayGatewayCredentials(ctx clingy.Context, credentials edge.Credentials, format string, awsProfile string) (err error) {
|
||||
func DisplayGatewayCredentials(ctx context.Context, credentials edge.Credentials, format string, awsProfile string) (err error) {
|
||||
switch format {
|
||||
case "env": // export / set compatible format
|
||||
// note that AWS_ENDPOINT configuration is not natively utilized by the AWS CLI
|
||||
_, err = fmt.Fprintf(ctx, "AWS_ACCESS_KEY_ID=%s\n"+
|
||||
_, err = fmt.Fprintf(clingy.Stdout(ctx), "AWS_ACCESS_KEY_ID=%s\n"+
|
||||
"AWS_SECRET_ACCESS_KEY=%s\n"+
|
||||
"AWS_ENDPOINT=%s\n",
|
||||
credentials.AccessKeyID, credentials.SecretKey, credentials.Endpoint)
|
||||
@ -295,13 +295,13 @@ func DisplayGatewayCredentials(ctx clingy.Context, credentials edge.Credentials,
|
||||
profile := ""
|
||||
if awsProfile != "" {
|
||||
profile = " --profile " + awsProfile
|
||||
_, err = fmt.Fprintf(ctx, "aws configure %s\n", profile)
|
||||
_, err = fmt.Fprintf(clingy.Stdout(ctx), "aws configure %s\n", profile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// note that the endpoint_url configuration is not natively utilized by the AWS CLI
|
||||
_, err = fmt.Fprintf(ctx, "aws configure %s set aws_access_key_id %s\n"+
|
||||
_, err = fmt.Fprintf(clingy.Stdout(ctx), "aws configure %s set aws_access_key_id %s\n"+
|
||||
"aws configure %s set aws_secret_access_key %s\n"+
|
||||
"aws configure %s set s3.endpoint_url %s\n",
|
||||
profile, credentials.AccessKeyID, profile, credentials.SecretKey, profile, credentials.Endpoint)
|
||||
@ -309,7 +309,7 @@ func DisplayGatewayCredentials(ctx clingy.Context, credentials edge.Credentials,
|
||||
return err
|
||||
}
|
||||
default: // plain text
|
||||
_, err = fmt.Fprintf(ctx, "========== CREDENTIALS ===================================================================\n"+
|
||||
_, err = fmt.Fprintf(clingy.Stdout(ctx), "========== CREDENTIALS ===================================================================\n"+
|
||||
"Access Key ID: %s\n"+
|
||||
"Secret Key : %s\n"+
|
||||
"Endpoint : %s\n",
|
||||
|
@ -4,6 +4,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"runtime/debug"
|
||||
"strconv"
|
||||
@ -32,15 +33,15 @@ func (c *cmdVersion) Setup(params clingy.Parameters) {
|
||||
).(bool)
|
||||
}
|
||||
|
||||
func (c *cmdVersion) Execute(ctx clingy.Context) error {
|
||||
func (c *cmdVersion) Execute(ctx context.Context) error {
|
||||
if version.Build.Release {
|
||||
fmt.Fprintln(ctx, "Release build")
|
||||
fmt.Fprintln(clingy.Stdout(ctx), "Release build")
|
||||
} else {
|
||||
fmt.Fprintln(ctx, "Development build")
|
||||
fmt.Fprintln(clingy.Stdout(ctx), "Development build")
|
||||
}
|
||||
|
||||
{
|
||||
tw := newTabbedWriter(ctx.Stdout())
|
||||
tw := newTabbedWriter(clingy.Stdout(ctx))
|
||||
if !version.Build.Version.IsZero() {
|
||||
tw.WriteLine("Version:", version.Build.Version.String())
|
||||
}
|
||||
@ -53,14 +54,14 @@ func (c *cmdVersion) Execute(ctx clingy.Context) error {
|
||||
tw.Done()
|
||||
}
|
||||
|
||||
fmt.Fprintln(ctx)
|
||||
fmt.Fprintln(clingy.Stdout(ctx))
|
||||
|
||||
bi, ok := debug.ReadBuildInfo()
|
||||
if !ok {
|
||||
return errs.New("unable to read build info")
|
||||
}
|
||||
|
||||
tw := newTabbedWriter(ctx.Stdout(), "PATH", "VERSION")
|
||||
tw := newTabbedWriter(clingy.Stdout(ctx), "PATH", "VERSION")
|
||||
defer tw.Done()
|
||||
|
||||
tw.WriteLine(bi.Main.Path, bi.Main.Version)
|
||||
|
@ -136,7 +136,7 @@ func (ex *external) Dynamic(name string) (vals []string, err error) {
|
||||
}
|
||||
|
||||
// Wrap is called by clingy with the command to be executed.
|
||||
func (ex *external) Wrap(ctx clingy.Context, cmd clingy.Command) (err error) {
|
||||
func (ex *external) Wrap(ctx context.Context, cmd clingy.Command) (err error) {
|
||||
if err := ex.migrate(); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -149,8 +149,6 @@ func (ex *external) Wrap(ctx clingy.Context, cmd clingy.Command) (err error) {
|
||||
}
|
||||
}
|
||||
|
||||
ctxWrapped := ctx
|
||||
|
||||
if ex.tracing.traceAddress != "" {
|
||||
versionName := fmt.Sprintf("uplink-release-%s", version.Build.Version.String())
|
||||
if !version.Build.Release {
|
||||
@ -174,41 +172,23 @@ func (ex *external) Wrap(ctx clingy.Context, cmd clingy.Command) (err error) {
|
||||
trace := monkit.NewTrace(ex.tracing.traceID)
|
||||
trace.Set(rpctracing.Sampled, true)
|
||||
|
||||
var baseContext context.Context = ctx
|
||||
defer mon.Func().RemoteTrace(&baseContext, monkit.NewId(), trace)(&err)
|
||||
|
||||
ctxWrapped = &clingyWrapper{
|
||||
Context: baseContext,
|
||||
clx: ctx,
|
||||
}
|
||||
defer mon.Func().RemoteTrace(&ctx, monkit.NewId(), trace)(&err)
|
||||
}
|
||||
|
||||
return cmd.Execute(ctxWrapped)
|
||||
return cmd.Execute(ctx)
|
||||
}
|
||||
|
||||
// clingyWrapper lets one swap out the context.Context in a clingy.Context.
|
||||
type clingyWrapper struct {
|
||||
context.Context
|
||||
clx clingy.Context
|
||||
}
|
||||
|
||||
func (cw *clingyWrapper) Read(p []byte) (int, error) { return cw.clx.Read(p) }
|
||||
func (cw *clingyWrapper) Write(p []byte) (int, error) { return cw.clx.Write(p) }
|
||||
func (cw *clingyWrapper) Stdin() io.Reader { return cw.clx.Stdin() }
|
||||
func (cw *clingyWrapper) Stdout() io.Writer { return cw.clx.Stdout() }
|
||||
func (cw *clingyWrapper) Stderr() io.Writer { return cw.clx.Stderr() }
|
||||
|
||||
// PromptInput gets a line of input text from the user and returns an error if
|
||||
// interactive mode is disabled.
|
||||
func (ex *external) PromptInput(ctx clingy.Context, prompt string) (input string, err error) {
|
||||
func (ex *external) PromptInput(ctx context.Context, prompt string) (input string, err error) {
|
||||
if !ex.interactive {
|
||||
return "", errs.New("required user input in non-interactive setting")
|
||||
}
|
||||
fmt.Fprint(ctx.Stdout(), prompt, " ")
|
||||
fmt.Fprint(clingy.Stdout(ctx), prompt, " ")
|
||||
var buf []byte
|
||||
var tmp [1]byte
|
||||
for {
|
||||
_, err := ctx.Stdin().Read(tmp[:])
|
||||
_, err := clingy.Stdin(ctx).Read(tmp[:])
|
||||
if errors.Is(err, io.EOF) {
|
||||
break
|
||||
} else if err != nil {
|
||||
@ -224,37 +204,37 @@ func (ex *external) PromptInput(ctx clingy.Context, prompt string) (input string
|
||||
// PromptInput gets a line of secret input from the user twice to ensure that
|
||||
// it is the same value, and returns an error if interactive mode is disabled
|
||||
// or if the prompt cannot be put into a mode where the typing is not echoed.
|
||||
func (ex *external) PromptSecret(ctx clingy.Context, prompt string) (secret string, err error) {
|
||||
func (ex *external) PromptSecret(ctx context.Context, prompt string) (secret string, err error) {
|
||||
if !ex.interactive {
|
||||
return "", errs.New("required secret input in non-interactive setting")
|
||||
}
|
||||
|
||||
fh, ok := ctx.Stdin().(interface{ Fd() uintptr })
|
||||
fh, ok := clingy.Stdin(ctx).(interface{ Fd() uintptr })
|
||||
if !ok {
|
||||
return "", errs.New("unable to request secret from stdin")
|
||||
}
|
||||
fd := int(fh.Fd())
|
||||
|
||||
for {
|
||||
fmt.Fprint(ctx.Stdout(), prompt, " ")
|
||||
fmt.Fprint(clingy.Stdout(ctx), prompt, " ")
|
||||
|
||||
first, err := term.ReadPassword(fd)
|
||||
if err != nil {
|
||||
return "", errs.New("unable to request secret from stdin: %w", err)
|
||||
}
|
||||
fmt.Fprintln(ctx.Stdout())
|
||||
fmt.Fprintln(clingy.Stdout(ctx))
|
||||
|
||||
fmt.Fprint(ctx.Stdout(), "Again: ")
|
||||
fmt.Fprint(clingy.Stdout(ctx), "Again: ")
|
||||
|
||||
second, err := term.ReadPassword(fd)
|
||||
if err != nil {
|
||||
return "", errs.New("unable to request secret from stdin: %w", err)
|
||||
}
|
||||
fmt.Fprintln(ctx.Stdout())
|
||||
fmt.Fprintln(clingy.Stdout(ctx))
|
||||
|
||||
if string(first) != string(second) {
|
||||
fmt.Fprintln(ctx.Stdout(), "Values did not match. Try again.")
|
||||
fmt.Fprintln(ctx.Stdout())
|
||||
fmt.Fprintln(clingy.Stdout(ctx), "Values did not match. Try again.")
|
||||
fmt.Fprintln(clingy.Stdout(ctx))
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -164,7 +164,7 @@ func (ex *external) RequestAccess(ctx context.Context, satelliteAddr, apiKey, pa
|
||||
return access, nil
|
||||
}
|
||||
|
||||
func (ex *external) ExportAccess(ctx clingy.Context, access *uplink.Access, filename string) error {
|
||||
func (ex *external) ExportAccess(ctx context.Context, access *uplink.Access, filename string) error {
|
||||
serialized, err := access.Serialize()
|
||||
if err != nil {
|
||||
return errs.Wrap(err)
|
||||
@ -192,6 +192,6 @@ func (ex *external) ExportAccess(ctx clingy.Context, access *uplink.Access, file
|
||||
return errs.Wrap(err)
|
||||
}
|
||||
|
||||
fmt.Fprintln(ctx, "Exported access to:", filename)
|
||||
fmt.Fprintln(clingy.Stdout(ctx), "Exported access to:", filename)
|
||||
return nil
|
||||
}
|
||||
|
@ -4,15 +4,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/zeebo/clingy"
|
||||
"github.com/zeebo/errs"
|
||||
|
||||
"storj.io/storj/cmd/uplink/ulext"
|
||||
)
|
||||
|
||||
func saveInitialConfig(ctx clingy.Context, ex ulext.External) error {
|
||||
func saveInitialConfig(ctx context.Context, ex ulext.External) error {
|
||||
answer, err := ex.PromptInput(ctx, `With your permission, Storj can `+
|
||||
`automatically collect analytics information from your uplink CLI to `+
|
||||
`help improve the quality and performance of our products. This `+
|
||||
|
@ -13,7 +13,6 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/zeebo/clingy"
|
||||
"github.com/zeebo/errs"
|
||||
|
||||
"storj.io/common/rpc/rpcpool"
|
||||
@ -32,13 +31,13 @@ type External interface {
|
||||
GetAccessInfo(required bool) (string, map[string]string, error)
|
||||
SaveAccessInfo(defaultName string, accesses map[string]string) error
|
||||
RequestAccess(ctx context.Context, satelliteAddress, apiKey, passphrase string) (*uplink.Access, error)
|
||||
ExportAccess(ctx clingy.Context, access *uplink.Access, filename string) error
|
||||
ExportAccess(ctx context.Context, access *uplink.Access, filename string) error
|
||||
|
||||
ConfigFile() string
|
||||
SaveConfig(values map[string]string) error
|
||||
|
||||
PromptInput(ctx clingy.Context, prompt string) (input string, err error)
|
||||
PromptSecret(ctx clingy.Context, prompt string) (secret string, err error)
|
||||
PromptInput(ctx context.Context, prompt string) (input string, err error)
|
||||
PromptSecret(ctx context.Context, prompt string) (secret string, err error)
|
||||
}
|
||||
|
||||
// Options contains all of the possible options for opening a filesystem or project.
|
||||
|
@ -8,8 +8,6 @@ import (
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"github.com/zeebo/clingy"
|
||||
|
||||
"storj.io/storj/cmd/uplink/ulloc"
|
||||
"storj.io/uplink"
|
||||
)
|
||||
@ -40,10 +38,10 @@ func (ro *RemoveOptions) isPending() bool { return ro != nil && ro.Pending }
|
||||
// Filesystem represents either the local filesystem or the data backed by a project.
|
||||
type Filesystem interface {
|
||||
Close() error
|
||||
Open(ctx clingy.Context, loc ulloc.Location) (MultiReadHandle, error)
|
||||
Create(ctx clingy.Context, loc ulloc.Location, opts *CreateOptions) (MultiWriteHandle, error)
|
||||
Move(ctx clingy.Context, source, dest ulloc.Location) error
|
||||
Copy(ctx clingy.Context, source, dest ulloc.Location) error
|
||||
Open(ctx context.Context, loc ulloc.Location) (MultiReadHandle, error)
|
||||
Create(ctx context.Context, loc ulloc.Location, opts *CreateOptions) (MultiWriteHandle, error)
|
||||
Move(ctx context.Context, source, dest ulloc.Location) error
|
||||
Copy(ctx context.Context, source, dest ulloc.Location) error
|
||||
Remove(ctx context.Context, loc ulloc.Location, opts *RemoveOptions) error
|
||||
List(ctx context.Context, prefix ulloc.Location, opts *ListOptions) (ObjectIterator, error)
|
||||
IsLocalDir(ctx context.Context, loc ulloc.Location) bool
|
||||
|
@ -32,27 +32,27 @@ func (m *Mixed) Close() error {
|
||||
}
|
||||
|
||||
// Open returns a MultiReadHandle to either a local file, remote object, or stdin.
|
||||
func (m *Mixed) Open(ctx clingy.Context, loc ulloc.Location) (MultiReadHandle, error) {
|
||||
func (m *Mixed) Open(ctx context.Context, loc ulloc.Location) (MultiReadHandle, error) {
|
||||
if bucket, key, ok := loc.RemoteParts(); ok {
|
||||
return m.remote.Open(ctx, bucket, key)
|
||||
} else if path, ok := loc.LocalParts(); ok {
|
||||
return m.local.Open(ctx, path)
|
||||
}
|
||||
return newStdMultiReadHandle(ctx.Stdin()), nil
|
||||
return newStdMultiReadHandle(clingy.Stdin(ctx)), nil
|
||||
}
|
||||
|
||||
// Create returns a WriteHandle to either a local file, remote object, or stdout.
|
||||
func (m *Mixed) Create(ctx clingy.Context, loc ulloc.Location, opts *CreateOptions) (MultiWriteHandle, error) {
|
||||
func (m *Mixed) Create(ctx context.Context, loc ulloc.Location, opts *CreateOptions) (MultiWriteHandle, error) {
|
||||
if bucket, key, ok := loc.RemoteParts(); ok {
|
||||
return m.remote.Create(ctx, bucket, key, opts)
|
||||
} else if path, ok := loc.LocalParts(); ok {
|
||||
return m.local.Create(ctx, path)
|
||||
}
|
||||
return newStdMultiWriteHandle(ctx.Stdout()), nil
|
||||
return newStdMultiWriteHandle(clingy.Stdout(ctx)), nil
|
||||
}
|
||||
|
||||
// Move moves either a local file or remote object.
|
||||
func (m *Mixed) Move(ctx clingy.Context, source, dest ulloc.Location) error {
|
||||
func (m *Mixed) Move(ctx context.Context, source, dest ulloc.Location) error {
|
||||
if oldbucket, oldkey, ok := source.RemoteParts(); ok {
|
||||
if newbucket, newkey, ok := dest.RemoteParts(); ok {
|
||||
return m.remote.Move(ctx, oldbucket, oldkey, newbucket, newkey)
|
||||
@ -66,7 +66,7 @@ func (m *Mixed) Move(ctx clingy.Context, source, dest ulloc.Location) error {
|
||||
}
|
||||
|
||||
// Copy copies either a local file or remote object.
|
||||
func (m *Mixed) Copy(ctx clingy.Context, source, dest ulloc.Location) error {
|
||||
func (m *Mixed) Copy(ctx context.Context, source, dest ulloc.Location) error {
|
||||
if oldbucket, oldkey, ok := source.RemoteParts(); ok {
|
||||
if newbucket, newkey, ok := dest.RemoteParts(); ok {
|
||||
return m.remote.Copy(ctx, oldbucket, oldkey, newbucket, newkey)
|
||||
|
@ -82,7 +82,7 @@ func (st State) Run(t *testing.T, args ...string) Result {
|
||||
Stdout: &stdout,
|
||||
Stderr: &stderr,
|
||||
|
||||
Wrap: func(ctx clingy.Context, cmd clingy.Command) error {
|
||||
Wrap: func(ctx context.Context, cmd clingy.Command) error {
|
||||
for _, opt := range st.opts {
|
||||
opt.fn(t, ctx, cs)
|
||||
}
|
||||
@ -164,26 +164,26 @@ type callbackState struct {
|
||||
|
||||
// ExecuteOption allows one to control the environment that a command executes in.
|
||||
type ExecuteOption struct {
|
||||
fn func(t *testing.T, ctx clingy.Context, cs *callbackState)
|
||||
fn func(t *testing.T, ctx context.Context, cs *callbackState)
|
||||
}
|
||||
|
||||
// WithFilesystem lets one do arbitrary setup on the filesystem in a callback.
|
||||
func WithFilesystem(cb func(t *testing.T, ctx clingy.Context, fs ulfs.Filesystem)) ExecuteOption {
|
||||
return ExecuteOption{func(t *testing.T, ctx clingy.Context, cs *callbackState) {
|
||||
func WithFilesystem(cb func(t *testing.T, ctx context.Context, fs ulfs.Filesystem)) ExecuteOption {
|
||||
return ExecuteOption{func(t *testing.T, ctx context.Context, cs *callbackState) {
|
||||
cb(t, ctx, cs.fs)
|
||||
}}
|
||||
}
|
||||
|
||||
// WithBucket ensures the bucket exists.
|
||||
func WithBucket(name string) ExecuteOption {
|
||||
return ExecuteOption{func(_ *testing.T, _ clingy.Context, cs *callbackState) {
|
||||
return ExecuteOption{func(_ *testing.T, _ context.Context, cs *callbackState) {
|
||||
cs.rfs.ensureBucket(name)
|
||||
}}
|
||||
}
|
||||
|
||||
// WithStdin sets the command to execute with the provided string as standard input.
|
||||
func WithStdin(stdin string) ExecuteOption {
|
||||
return ExecuteOption{func(_ *testing.T, _ clingy.Context, cs *callbackState) {
|
||||
return ExecuteOption{func(_ *testing.T, _ context.Context, cs *callbackState) {
|
||||
cs.stdin = stdin
|
||||
}}
|
||||
}
|
||||
@ -191,7 +191,7 @@ func WithStdin(stdin string) ExecuteOption {
|
||||
// WithFile sets the command to execute with a file created at the given location.
|
||||
func WithFile(location string, contents ...string) ExecuteOption {
|
||||
contents = append([]string(nil), contents...)
|
||||
return ExecuteOption{func(t *testing.T, ctx clingy.Context, cs *callbackState) {
|
||||
return ExecuteOption{func(t *testing.T, ctx context.Context, cs *callbackState) {
|
||||
loc, err := ulloc.Parse(location)
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -224,7 +224,7 @@ func WithFile(location string, contents ...string) ExecuteOption {
|
||||
// WithPendingFile sets the command to execute with a pending upload happening to
|
||||
// the provided location.
|
||||
func WithPendingFile(location string) ExecuteOption {
|
||||
return ExecuteOption{func(t *testing.T, ctx clingy.Context, cs *callbackState) {
|
||||
return ExecuteOption{func(t *testing.T, ctx context.Context, cs *callbackState) {
|
||||
loc, err := ulloc.Parse(location)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
2
go.mod
2
go.mod
@ -36,7 +36,7 @@ require (
|
||||
github.com/stripe/stripe-go/v72 v72.51.0
|
||||
github.com/vivint/infectious v0.0.0-20200605153912-25a574ae18a3
|
||||
github.com/zeebo/assert v1.3.0
|
||||
github.com/zeebo/clingy v0.0.0-20220412150312-389f1ba2553d
|
||||
github.com/zeebo/clingy v0.0.0-20220825183239-b8a4c2e29e63
|
||||
github.com/zeebo/errs v1.3.0
|
||||
github.com/zeebo/ini v0.0.0-20210331155437-86af75b4f524
|
||||
go.etcd.io/bbolt v1.3.5
|
||||
|
4
go.sum
4
go.sum
@ -586,8 +586,8 @@ github.com/zeebo/assert v1.3.0 h1:g7C04CbJuIDKNPFHmsk4hwZDO5O+kntRxzaUoNXj+IQ=
|
||||
github.com/zeebo/assert v1.3.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0=
|
||||
github.com/zeebo/blake3 v0.2.3 h1:TFoLXsjeXqRNFxSbk35Dk4YtszE/MQQGK10BH4ptoTg=
|
||||
github.com/zeebo/blake3 v0.2.3/go.mod h1:mjJjZpnsyIVtVgTOSpJ9vmRE4wgDeyt2HU3qXvvKCaQ=
|
||||
github.com/zeebo/clingy v0.0.0-20220412150312-389f1ba2553d h1:TiHczaYDVg3BomGW3IK8JGPJJVB7AXJ5kntuhrFyO54=
|
||||
github.com/zeebo/clingy v0.0.0-20220412150312-389f1ba2553d/go.mod h1:MHEhXvEfewflU7SSVKHI7nkdU+fpyxZ5XPPzj+5gYNw=
|
||||
github.com/zeebo/clingy v0.0.0-20220825183239-b8a4c2e29e63 h1:Fd4fMKAn1N0ko1YCW+kYmd+EM8AdYxNRYMYGNuV+ijM=
|
||||
github.com/zeebo/clingy v0.0.0-20220825183239-b8a4c2e29e63/go.mod h1:MHEhXvEfewflU7SSVKHI7nkdU+fpyxZ5XPPzj+5gYNw=
|
||||
github.com/zeebo/errs v1.1.1/go.mod h1:Yj8dHrUQwls1bF3dr/vcSIu+qf4mI7idnTcHfoACc6I=
|
||||
github.com/zeebo/errs v1.2.2/go.mod h1:sgbWHsvVuTPHcqJJGQ1WhI5KbWlHYz+2+2C/LSEtCw4=
|
||||
github.com/zeebo/errs v1.3.0 h1:hmiaKqgYZzcVgRL1Vkc1Mn2914BbzB0IBxs+ebeutGs=
|
||||
|
@ -843,7 +843,7 @@ github.com/zeebo/assert v1.3.0 h1:g7C04CbJuIDKNPFHmsk4hwZDO5O+kntRxzaUoNXj+IQ=
|
||||
github.com/zeebo/assert v1.3.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0=
|
||||
github.com/zeebo/blake3 v0.2.3 h1:TFoLXsjeXqRNFxSbk35Dk4YtszE/MQQGK10BH4ptoTg=
|
||||
github.com/zeebo/blake3 v0.2.3/go.mod h1:mjJjZpnsyIVtVgTOSpJ9vmRE4wgDeyt2HU3qXvvKCaQ=
|
||||
github.com/zeebo/clingy v0.0.0-20220412150312-389f1ba2553d/go.mod h1:MHEhXvEfewflU7SSVKHI7nkdU+fpyxZ5XPPzj+5gYNw=
|
||||
github.com/zeebo/clingy v0.0.0-20220825183239-b8a4c2e29e63/go.mod h1:MHEhXvEfewflU7SSVKHI7nkdU+fpyxZ5XPPzj+5gYNw=
|
||||
github.com/zeebo/errs v1.1.1/go.mod h1:Yj8dHrUQwls1bF3dr/vcSIu+qf4mI7idnTcHfoACc6I=
|
||||
github.com/zeebo/errs v1.2.2/go.mod h1:sgbWHsvVuTPHcqJJGQ1WhI5KbWlHYz+2+2C/LSEtCw4=
|
||||
github.com/zeebo/errs v1.3.0 h1:hmiaKqgYZzcVgRL1Vkc1Mn2914BbzB0IBxs+ebeutGs=
|
||||
|
@ -1028,7 +1028,7 @@ github.com/zeebo/assert v1.3.0 h1:g7C04CbJuIDKNPFHmsk4hwZDO5O+kntRxzaUoNXj+IQ=
|
||||
github.com/zeebo/assert v1.3.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0=
|
||||
github.com/zeebo/blake3 v0.2.3 h1:TFoLXsjeXqRNFxSbk35Dk4YtszE/MQQGK10BH4ptoTg=
|
||||
github.com/zeebo/blake3 v0.2.3/go.mod h1:mjJjZpnsyIVtVgTOSpJ9vmRE4wgDeyt2HU3qXvvKCaQ=
|
||||
github.com/zeebo/clingy v0.0.0-20220412150312-389f1ba2553d/go.mod h1:MHEhXvEfewflU7SSVKHI7nkdU+fpyxZ5XPPzj+5gYNw=
|
||||
github.com/zeebo/clingy v0.0.0-20220825183239-b8a4c2e29e63/go.mod h1:MHEhXvEfewflU7SSVKHI7nkdU+fpyxZ5XPPzj+5gYNw=
|
||||
github.com/zeebo/errs v1.1.1/go.mod h1:Yj8dHrUQwls1bF3dr/vcSIu+qf4mI7idnTcHfoACc6I=
|
||||
github.com/zeebo/errs v1.2.2/go.mod h1:sgbWHsvVuTPHcqJJGQ1WhI5KbWlHYz+2+2C/LSEtCw4=
|
||||
github.com/zeebo/errs v1.3.0 h1:hmiaKqgYZzcVgRL1Vkc1Mn2914BbzB0IBxs+ebeutGs=
|
||||
|
Loading…
Reference in New Issue
Block a user