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:
Márton Elek 2022-08-30 11:51:31 +02:00 committed by Storj Robot
parent 47301e5718
commit ea1408f7a8
32 changed files with 163 additions and 164 deletions

View File

@ -4,6 +4,7 @@
package main package main
import ( import (
"context"
"fmt" "fmt"
"strconv" "strconv"
@ -36,7 +37,7 @@ func (am *accessMaker) Setup(params clingy.Parameters, ex ulext.External) {
).(bool) ).(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) defaultName, accesses, err := am.ex.GetAccessInfo(false)
if err != nil { if err != nil {
return nil, err return nil, err
@ -68,7 +69,7 @@ func (am *accessMaker) Execute(ctx clingy.Context, name string, access *uplink.A
return nil, errs.Wrap(err) 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 return access, nil

View File

@ -4,6 +4,7 @@
package main package main
import ( import (
"context"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"strconv" "strconv"
@ -45,7 +46,7 @@ func (c *cmdAccessCreate) Setup(params clingy.Parameters) {
c.am.Setup(params, c.ex) 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.satelliteAddr == "" {
if c.passphraseStdin { if c.passphraseStdin {
return errs.New("Must specify the satellite address as a flag when passphrase-stdin is set.") 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 var passphrase string
if c.passphraseStdin { if c.passphraseStdin {
stdinData, err := ioutil.ReadAll(ctx.Stdin()) stdinData, err := ioutil.ReadAll(clingy.Stdin(ctx))
if err != nil { if err != nil {
return errs.Wrap(err) return errs.Wrap(err)
} }
@ -106,7 +107,7 @@ func (c *cmdAccessCreate) Execute(ctx clingy.Context) (err error) {
return errs.Wrap(err) return errs.Wrap(err)
} }
fmt.Fprintln(ctx, serialized) fmt.Fprintln(clingy.Stdout(ctx), serialized)
return nil return nil
} }

View File

@ -4,6 +4,8 @@
package main package main
import ( import (
"context"
"github.com/zeebo/clingy" "github.com/zeebo/clingy"
"github.com/zeebo/errs" "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) 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 == "" { if c.filename == "" {
return errs.New("Must specify a filename to write to.") return errs.New("Must specify a filename to write to.")
} }

View File

@ -4,6 +4,8 @@
package main package main
import ( import (
"context"
"github.com/zeebo/clingy" "github.com/zeebo/clingy"
"github.com/zeebo/errs" "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) 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 == "" { if c.name == "" {
return errs.New("Must specify a name to import the access as.") return errs.New("Must specify a name to import the access as.")
} }

View File

@ -4,6 +4,7 @@
package main package main
import ( import (
"context"
"encoding/base64" "encoding/base64"
"encoding/json" "encoding/json"
"fmt" "fmt"
@ -37,7 +38,7 @@ func (c *cmdAccessInspect) Setup(params clingy.Parameters) {
} }
// Execute runs the command. // Execute runs the command.
func (c *cmdAccessInspect) Execute(ctx clingy.Context) error { func (c *cmdAccessInspect) Execute(ctx context.Context) error {
toOpen := "" toOpen := ""
if c.access != nil { if c.access != nil {
toOpen = *c.access toOpen = *c.access
@ -96,7 +97,7 @@ func (c *cmdAccessInspect) Execute(ctx clingy.Context) error {
return err return err
} }
fmt.Fprintln(ctx, string(bs)) fmt.Fprintln(clingy.Stdout(ctx), string(bs))
return nil return nil
} }

View File

@ -4,6 +4,7 @@
package main package main
import ( import (
"context"
"sort" "sort"
"strconv" "strconv"
"strings" "strings"
@ -31,7 +32,7 @@ func (c *cmdAccessList) Setup(params clingy.Parameters) {
).(bool) ).(bool)
} }
func (c *cmdAccessList) Execute(ctx clingy.Context) error { func (c *cmdAccessList) Execute(ctx context.Context) error {
defaultName, accesses, err := c.ex.GetAccessInfo(true) defaultName, accesses, err := c.ex.GetAccessInfo(true)
if err != nil { if err != nil {
return err return err
@ -39,9 +40,9 @@ func (c *cmdAccessList) Execute(ctx clingy.Context) error {
var tw *tabbedWriter var tw *tabbedWriter
if c.verbose { if c.verbose {
tw = newTabbedWriter(ctx.Stdout(), "CURRENT", "NAME", "SATELLITE", "VALUE") tw = newTabbedWriter(clingy.Stdout(ctx), "CURRENT", "NAME", "SATELLITE", "VALUE")
} else { } else {
tw = newTabbedWriter(ctx.Stdout(), "CURRENT", "NAME", "SATELLITE") tw = newTabbedWriter(clingy.Stdout(ctx), "CURRENT", "NAME", "SATELLITE")
} }
defer tw.Done() defer tw.Done()

View File

@ -4,6 +4,7 @@
package main package main
import ( import (
"context"
"strconv" "strconv"
"github.com/zeebo/clingy" "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) 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 := "" accessNameOrValue := ""
if c.accessNameOrValue != nil && len(*c.accessNameOrValue) > 0 { if c.accessNameOrValue != nil && len(*c.accessNameOrValue) > 0 {
accessNameOrValue = *c.accessNameOrValue accessNameOrValue = *c.accessNameOrValue

View File

@ -4,6 +4,7 @@
package main package main
import ( import (
"context"
"fmt" "fmt"
"github.com/zeebo/clingy" "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) 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) defaultName, accesses, err := c.ex.GetAccessInfo(true)
if err != nil { if err != nil {
return err return err
@ -44,7 +45,7 @@ func (c *cmdAccessRemove) Execute(ctx clingy.Context) error {
return err 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 return nil
} }

View File

@ -4,6 +4,7 @@
package main package main
import ( import (
"context"
"fmt" "fmt"
"github.com/zeebo/clingy" "github.com/zeebo/clingy"
@ -36,7 +37,7 @@ func (c *cmdAccessRestrict) Setup(params clingy.Parameters) {
c.am.perms.Setup(params, true) 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) access, err := c.ex.OpenAccess(c.access)
if err != nil { if err != nil {
return err return err
@ -56,6 +57,6 @@ func (c *cmdAccessRestrict) Execute(ctx clingy.Context) error {
return errs.Wrap(err) return errs.Wrap(err)
} }
fmt.Fprintln(ctx, serialized) fmt.Fprintln(clingy.Stdout(ctx), serialized)
return nil return nil
} }

View File

@ -4,6 +4,7 @@
package main package main
import ( import (
"context"
"fmt" "fmt"
"github.com/zeebo/clingy" "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) 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) project, err := c.ex.OpenProject(ctx, c.access)
if err != nil { if err != nil {
return err return err
@ -43,7 +44,7 @@ func (c *cmdAccessRevoke) Execute(ctx clingy.Context) error {
return err return err
} }
fmt.Fprintf(ctx, "Revoked access %q\n", c.revokee) fmt.Fprintf(clingy.Stdout(ctx), "Revoked access %q\n", c.revokee)
return nil return nil
} }

View File

@ -4,6 +4,7 @@
package main package main
import ( import (
"context"
"fmt" "fmt"
"strings" "strings"
@ -37,7 +38,7 @@ func (c *cmdAccessSetup) Setup(params clingy.Parameters) {
c.am.Setup(params, c.ex) 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]:") name, err := c.ex.PromptInput(ctx, "Enter name to import as [default: main]:")
if err != nil { if err != nil {
return errs.Wrap(err) 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):") answer, err := c.ex.PromptInput(ctx, "Would you like S3 backwards-compatible Gateway credentials? (y/N):")
if err != nil { if err != nil {

View File

@ -4,6 +4,7 @@
package main package main
import ( import (
"context"
"fmt" "fmt"
"github.com/zeebo/clingy" "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) 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) _, accesses, err := c.ex.GetAccessInfo(true)
if err != nil { if err != nil {
return err return err
@ -38,7 +39,7 @@ func (c *cmdAccessUse) Execute(ctx clingy.Context) error {
return err 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 return nil
} }

View File

@ -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) 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{ fs, err := c.ex.OpenFilesystem(ctx, c.access, ulext.ConnectionPoolOptions(rpcpool.Options{
Capacity: 100 * c.parallelism, Capacity: 100 * c.parallelism,
KeyCapacity: 5, KeyCapacity: 5,
@ -150,13 +150,13 @@ func (c *cmdCp) Execute(ctx clingy.Context) error {
c.dest = joinDestWith(c.dest, base) c.dest = joinDestWith(c.dest, base)
if !c.source.Std() && !c.dest.Std() { 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) 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() { if c.source.Std() || c.dest.Std() {
return errs.New("cannot recursively copy to stdin/stdout") 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) dest := joinDestWith(c.dest, rel)
ok := limiter.Go(ctx, func() { 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 { 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) addError(err)
} }
}) })
@ -223,7 +223,7 @@ func (c *cmdCp) copyRecursive(ctx clingy.Context, fs ulfs.Filesystem) error {
return nil 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 { if c.dryrun {
return nil return nil
} }
@ -254,7 +254,7 @@ func (c *cmdCp) copyFile(ctx clingy.Context, fs ulfs.Filesystem, source, dest ul
var bar *progressbar.ProgressBar var bar *progressbar.ProgressBar
if progress && !c.dest.Std() { if progress && !c.dest.Std() {
bar = progressbar.New64(0).SetWriter(ctx.Stdout()) bar = progressbar.New64(0).SetWriter(clingy.Stdout(ctx))
defer bar.Finish() defer bar.Finish()
} }
@ -313,7 +313,7 @@ func joinDestWith(dest ulloc.Location, suffix string) ulloc.Location {
} }
func (c *cmdCp) parallelCopy( func (c *cmdCp) parallelCopy(
clctx clingy.Context, clctx context.Context,
dst ulfs.MultiWriteHandle, dst ulfs.MultiWriteHandle,
src ulfs.MultiReadHandle, src ulfs.MultiReadHandle,
p int, chunkSize int64, p int, chunkSize int64,

View File

@ -4,6 +4,7 @@
package main package main
import ( import (
"context"
"encoding/json" "encoding/json"
"strconv" "strconv"
"time" "time"
@ -63,14 +64,14 @@ func (c *cmdLs) Setup(params clingy.Parameters) {
).(*ulloc.Location) ).(*ulloc.Location)
} }
func (c *cmdLs) Execute(ctx clingy.Context) error { func (c *cmdLs) Execute(ctx context.Context) error {
if c.prefix == nil { if c.prefix == nil {
return c.listBuckets(ctx) return c.listBuckets(ctx)
} }
return c.listLocation(ctx, *c.prefix) 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) project, err := c.ex.OpenProject(ctx, c.access)
if err != nil { if err != nil {
return err 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)) fs, err := c.ex.OpenFilesystem(ctx, c.access, ulext.BypassEncryption(c.encrypted))
if err != nil { if err != nil {
return err 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) { func (c *cmdLs) printTabbedBucket(ctx context.Context, iter *uplink.BucketIterator) (err error) {
tw := newTabbedWriter(ctx.Stdout(), "CREATED", "NAME") tw := newTabbedWriter(clingy.Stdout(ctx), "CREATED", "NAME")
defer tw.Done() defer tw.Done()
for iter.Next() { for iter.Next() {
@ -131,8 +132,8 @@ func (c *cmdLs) printTabbedBucket(ctx clingy.Context, iter *uplink.BucketIterato
return iter.Err() return iter.Err()
} }
func (c *cmdLs) printJSONBucket(ctx clingy.Context, iter *uplink.BucketIterator) (err error) { func (c *cmdLs) printJSONBucket(ctx context.Context, iter *uplink.BucketIterator) (err error) {
jw := json.NewEncoder(ctx.Stdout()) jw := json.NewEncoder(clingy.Stdout(ctx))
for iter.Next() { for iter.Next() {
obj := iter.Item() obj := iter.Item()
@ -145,13 +146,13 @@ func (c *cmdLs) printJSONBucket(ctx clingy.Context, iter *uplink.BucketIterator)
return iter.Err() 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"} headers := []string{"KIND", "CREATED", "SIZE", "KEY"}
if c.expanded { if c.expanded {
headers = append(headers, "EXPIRES", "META") headers = append(headers, "EXPIRES", "META")
} }
tw := newTabbedWriter(ctx.Stdout(), headers...) tw := newTabbedWriter(clingy.Stdout(ctx), headers...)
defer tw.Done() defer tw.Done()
// iterate and print the results // iterate and print the results
@ -176,8 +177,8 @@ func (c *cmdLs) printTabbedLocation(ctx clingy.Context, iter ulfs.ObjectIterator
return iter.Err() return iter.Err()
} }
func (c *cmdLs) printJSONLocation(ctx clingy.Context, iter ulfs.ObjectIterator) (err error) { func (c *cmdLs) printJSONLocation(ctx context.Context, iter ulfs.ObjectIterator) (err error) {
jw := json.NewEncoder(ctx.Stdout()) jw := json.NewEncoder(clingy.Stdout(ctx))
for iter.Next() { for iter.Next() {
obj := iter.Item() obj := iter.Item()

View File

@ -4,6 +4,8 @@
package main package main
import ( import (
"context"
"github.com/zeebo/clingy" "github.com/zeebo/clingy"
"github.com/zeebo/errs" "github.com/zeebo/errs"
@ -36,7 +38,7 @@ func (c *cmdMb) Setup(params clingy.Parameters) {
).(string) ).(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) project, err := c.ex.OpenProject(ctx, c.access)
if err != nil { if err != nil {
return errs.Wrap(err) return errs.Wrap(err)

View File

@ -4,6 +4,7 @@
package main package main
import ( import (
"context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"strconv" "strconv"
@ -41,7 +42,7 @@ func (c *cmdMetaGet) Setup(params clingy.Parameters) {
c.entry = params.Arg("entry", "Metadata entry to get", clingy.Optional).(*string) 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)) project, err := c.ex.OpenProject(ctx, c.access, ulext.BypassEncryption(c.encrypted))
if err != nil { if err != nil {
return err return err
@ -64,12 +65,12 @@ func (c *cmdMetaGet) Execute(ctx clingy.Context) error {
return errs.New("entry %q does not exist", *c.entry) return errs.New("entry %q does not exist", *c.entry)
} }
fmt.Fprintln(ctx.Stdout(), value) fmt.Fprintln(clingy.Stdout(ctx), value)
return nil return nil
} }
if object.Custom == nil { if object.Custom == nil {
fmt.Fprintln(ctx.Stdout(), "{}") fmt.Fprintln(clingy.Stdout(ctx), "{}")
return nil return nil
} }
@ -78,6 +79,6 @@ func (c *cmdMetaGet) Execute(ctx clingy.Context) error {
return errs.Wrap(err) return errs.Wrap(err)
} }
fmt.Fprintln(ctx.Stdout(), string(data)) fmt.Fprintln(clingy.Stdout(ctx), string(data))
return nil return nil
} }

View File

@ -4,6 +4,7 @@
package main package main
import ( import (
"context"
"fmt" "fmt"
"io" "io"
"strconv" "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) 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) fs, err := c.ex.OpenFilesystem(ctx, c.access)
if err != nil { if err != nil {
return err return err
@ -113,7 +114,7 @@ func (c *cmdMv) Execute(ctx clingy.Context) error {
return c.moveFile(ctx, fs, c.source, c.dest) 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{ iter, err := fs.List(ctx, c.source, &ulfs.ListOptions{
Recursive: true, Recursive: true,
}) })
@ -166,11 +167,11 @@ func (c *cmdMv) moveRecursive(ctx clingy.Context, fs ulfs.Filesystem) error {
ok := limiter.Go(ctx, func() { ok := limiter.Go(ctx, func() {
if c.progress { 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 { 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) addError(err)
} }
}) })
@ -187,7 +188,7 @@ func (c *cmdMv) moveRecursive(ctx clingy.Context, fs ulfs.Filesystem) error {
return nil 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 { if c.dryrun {
return nil return nil
} }

View File

@ -4,6 +4,7 @@
package main package main
import ( import (
"context"
"fmt" "fmt"
"strconv" "strconv"
@ -38,7 +39,7 @@ func (c *cmdRb) Setup(params clingy.Parameters) {
).(ulloc.Location) ).(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) project, err := c.ex.OpenProject(ctx, c.access)
if err != nil { if err != nil {
return err return err
@ -62,6 +63,6 @@ func (c *cmdRb) Execute(ctx clingy.Context) error {
return err 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 return nil
} }

View File

@ -4,6 +4,7 @@
package main package main
import ( import (
"context"
"fmt" "fmt"
"io" "io"
"strconv" "strconv"
@ -62,7 +63,7 @@ func (c *cmdRm) Setup(params clingy.Parameters) {
).(ulloc.Location) ).(ulloc.Location)
} }
func (c *cmdRm) Execute(ctx clingy.Context) error { func (c *cmdRm) Execute(ctx context.Context) error {
if c.location.Local() { if c.location.Local() {
return errs.New("remove %v skipped: local delete", c.location) return errs.New("remove %v skipped: local delete", c.location)
} }
@ -81,7 +82,7 @@ func (c *cmdRm) Execute(ctx clingy.Context) error {
return err return err
} }
fmt.Fprintln(ctx.Stdout(), "removed", c.location) fmt.Fprintln(clingy.Stdout(ctx), "removed", c.location)
return nil return nil
} }
@ -121,10 +122,10 @@ func (c *cmdRm) Execute(ctx clingy.Context) error {
Pending: c.pending, Pending: c.pending,
}) })
if err != nil { if err != nil {
fprintln(ctx.Stderr(), "remove", loc, "failed:", err.Error()) fprintln(clingy.Stderr(ctx), "remove", loc, "failed:", err.Error())
addError(err) addError(err)
} else { } else {
fprintln(ctx.Stdout(), "removed", loc) fprintln(clingy.Stdout(ctx), "removed", loc)
} }
}) })
if !ok { if !ok {

View File

@ -63,7 +63,7 @@ func (c *cmdShare) Setup(params clingy.Parameters) {
c.ap.Setup(params, false) 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 { 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.") 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 c.register = true
if c.ap.notAfter.String() == "" { if c.ap.notAfter.String() == "" {
fmt.Fprintf(ctx, "It's not recommended to create a shared Access without an expiration date.") fmt.Fprintf(clingy.Stdout(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), "If you wish to do so anyway, please run this command with --not-after=none.")
return nil return nil
} }
@ -99,17 +99,17 @@ func (c *cmdShare) Execute(ctx clingy.Context) error {
return err return err
} }
fmt.Fprintf(ctx, "Sharing access to satellite %s\n", access.SatelliteAddress()) fmt.Fprintf(clingy.Stdout(ctx), "Sharing access to satellite %s\n", access.SatelliteAddress())
fmt.Fprintf(ctx, "=========== ACCESS RESTRICTIONS ==========================================================\n") fmt.Fprintf(clingy.Stdout(ctx), "=========== ACCESS RESTRICTIONS ==========================================================\n")
fmt.Fprintf(ctx, "Download : %s\n", formatPermission(c.ap.AllowDownload())) fmt.Fprintf(clingy.Stdout(ctx), "Download : %s\n", formatPermission(c.ap.AllowDownload()))
fmt.Fprintf(ctx, "Upload : %s\n", formatPermission(c.ap.AllowUpload())) fmt.Fprintf(clingy.Stdout(ctx), "Upload : %s\n", formatPermission(c.ap.AllowUpload()))
fmt.Fprintf(ctx, "Lists : %s\n", formatPermission(c.ap.AllowList())) fmt.Fprintf(clingy.Stdout(ctx), "Lists : %s\n", formatPermission(c.ap.AllowList()))
fmt.Fprintf(ctx, "Deletes : %s\n", formatPermission(c.ap.AllowDelete())) fmt.Fprintf(clingy.Stdout(ctx), "Deletes : %s\n", formatPermission(c.ap.AllowDelete()))
fmt.Fprintf(ctx, "NotBefore : %s\n", formatTimeRestriction(c.ap.notBefore)) fmt.Fprintf(clingy.Stdout(ctx), "NotBefore : %s\n", formatTimeRestriction(c.ap.notBefore))
fmt.Fprintf(ctx, "NotAfter : %s\n", formatTimeRestriction(c.ap.notAfter)) fmt.Fprintf(clingy.Stdout(ctx), "NotAfter : %s\n", formatTimeRestriction(c.ap.notAfter))
fmt.Fprintf(ctx, "Paths : %s\n", formatPaths(c.ap.prefixes)) fmt.Fprintf(clingy.Stdout(ctx), "Paths : %s\n", formatPaths(c.ap.prefixes))
fmt.Fprintf(ctx, "=========== SERIALIZED ACCESS WITH THE ABOVE RESTRICTIONS TO SHARE WITH OTHERS ===========\n") fmt.Fprintf(clingy.Stdout(ctx), "=========== SERIALIZED ACCESS WITH THE ABOVE RESTRICTIONS TO SHARE WITH OTHERS ===========\n")
fmt.Fprintf(ctx, "Access : %s\n", newAccessData) fmt.Fprintf(clingy.Stdout(ctx), "Access : %s\n", newAccessData)
if c.register { if c.register {
credentials, err := RegisterAccess(ctx, access, c.authService, c.public, c.caCert) 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 { if err != nil {
return err return err
} }
_, err = fmt.Fprintln(ctx, "Public Access: ", c.public) _, err = fmt.Fprintln(clingy.Stdout(ctx), "Public Access: ", c.public)
if err != nil { if err != nil {
return err 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 { if err := ioutil.WriteFile(exportTo, []byte(newAccessData+"\n"), 0600); err != nil {
return err return err
} }
fmt.Fprintln(ctx, "Exported to:", exportTo) fmt.Fprintln(clingy.Stdout(ctx), "Exported to:", exportTo)
} }
return nil return nil
@ -226,7 +226,7 @@ func RegisterAccess(ctx context.Context, access *uplink.Access, authService stri
} }
// Creates linksharing url for allowed path prefixes. // 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 { if len(prefixes) == 0 {
return errs.New("need at least a bucket to create a working linkshare URL") 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 return err
} }
fmt.Fprintf(ctx, "=========== BROWSER URL ==================================================================\n") fmt.Fprintf(clingy.Stdout(ctx), "=========== BROWSER URL ==================================================================\n")
if key != "" && key[len(key)-1:] != "/" { 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 return nil
} }
// Creates dns record info for allowed path prefixes. // 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 { if len(prefixes) == 0 {
return errs.New("need at least a bucket to create DNS records") 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) printStorjRoot = fmt.Sprintf("txt-%s\tIN\tTXT \tstorj-root:%s/%s", dns, bucket, key)
} }
fmt.Fprintf(ctx, "=========== DNS INFO =====================================================================\n") fmt.Fprintf(clingy.Stdout(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(clingy.Stdout(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(clingy.Stdout(ctx), "$ORIGIN example.com.\n")
fmt.Fprintf(ctx, "$TTL 3600\n") fmt.Fprintf(clingy.Stdout(ctx), "$TTL 3600\n")
fmt.Fprintf(ctx, "%s \tIN\tCNAME\t%s.\n", dns, CNAME.Host) fmt.Fprintf(clingy.Stdout(ctx), "%s \tIN\tCNAME\t%s.\n", dns, CNAME.Host)
fmt.Fprintln(ctx, printStorjRoot) fmt.Fprintln(clingy.Stdout(ctx), printStorjRoot)
fmt.Fprintf(ctx, "txt-%s\tIN\tTXT \tstorj-access:%s\n", dns, accessKey) fmt.Fprintf(clingy.Stdout(ctx), "txt-%s\tIN\tTXT \tstorj-access:%s\n", dns, accessKey)
return nil return nil
} }
// DisplayGatewayCredentials formats and writes credentials to stdout. // 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 { switch format {
case "env": // export / set compatible format case "env": // export / set compatible format
// note that AWS_ENDPOINT configuration is not natively utilized by the AWS CLI // 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_SECRET_ACCESS_KEY=%s\n"+
"AWS_ENDPOINT=%s\n", "AWS_ENDPOINT=%s\n",
credentials.AccessKeyID, credentials.SecretKey, credentials.Endpoint) credentials.AccessKeyID, credentials.SecretKey, credentials.Endpoint)
@ -295,13 +295,13 @@ func DisplayGatewayCredentials(ctx clingy.Context, credentials edge.Credentials,
profile := "" profile := ""
if awsProfile != "" { if awsProfile != "" {
profile = " --profile " + 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 { if err != nil {
return err return err
} }
} }
// note that the endpoint_url configuration is not natively utilized by the AWS CLI // 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 aws_secret_access_key %s\n"+
"aws configure %s set s3.endpoint_url %s\n", "aws configure %s set s3.endpoint_url %s\n",
profile, credentials.AccessKeyID, profile, credentials.SecretKey, profile, credentials.Endpoint) profile, credentials.AccessKeyID, profile, credentials.SecretKey, profile, credentials.Endpoint)
@ -309,7 +309,7 @@ func DisplayGatewayCredentials(ctx clingy.Context, credentials edge.Credentials,
return err return err
} }
default: // plain text default: // plain text
_, err = fmt.Fprintf(ctx, "========== CREDENTIALS ===================================================================\n"+ _, err = fmt.Fprintf(clingy.Stdout(ctx), "========== CREDENTIALS ===================================================================\n"+
"Access Key ID: %s\n"+ "Access Key ID: %s\n"+
"Secret Key : %s\n"+ "Secret Key : %s\n"+
"Endpoint : %s\n", "Endpoint : %s\n",

View File

@ -4,6 +4,7 @@
package main package main
import ( import (
"context"
"fmt" "fmt"
"runtime/debug" "runtime/debug"
"strconv" "strconv"
@ -32,15 +33,15 @@ func (c *cmdVersion) Setup(params clingy.Parameters) {
).(bool) ).(bool)
} }
func (c *cmdVersion) Execute(ctx clingy.Context) error { func (c *cmdVersion) Execute(ctx context.Context) error {
if version.Build.Release { if version.Build.Release {
fmt.Fprintln(ctx, "Release build") fmt.Fprintln(clingy.Stdout(ctx), "Release build")
} else { } 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() { if !version.Build.Version.IsZero() {
tw.WriteLine("Version:", version.Build.Version.String()) tw.WriteLine("Version:", version.Build.Version.String())
} }
@ -53,14 +54,14 @@ func (c *cmdVersion) Execute(ctx clingy.Context) error {
tw.Done() tw.Done()
} }
fmt.Fprintln(ctx) fmt.Fprintln(clingy.Stdout(ctx))
bi, ok := debug.ReadBuildInfo() bi, ok := debug.ReadBuildInfo()
if !ok { if !ok {
return errs.New("unable to read build info") return errs.New("unable to read build info")
} }
tw := newTabbedWriter(ctx.Stdout(), "PATH", "VERSION") tw := newTabbedWriter(clingy.Stdout(ctx), "PATH", "VERSION")
defer tw.Done() defer tw.Done()
tw.WriteLine(bi.Main.Path, bi.Main.Version) tw.WriteLine(bi.Main.Path, bi.Main.Version)

View File

@ -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. // 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 { if err := ex.migrate(); err != nil {
return err return err
} }
@ -149,8 +149,6 @@ func (ex *external) Wrap(ctx clingy.Context, cmd clingy.Command) (err error) {
} }
} }
ctxWrapped := ctx
if ex.tracing.traceAddress != "" { if ex.tracing.traceAddress != "" {
versionName := fmt.Sprintf("uplink-release-%s", version.Build.Version.String()) versionName := fmt.Sprintf("uplink-release-%s", version.Build.Version.String())
if !version.Build.Release { 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 := monkit.NewTrace(ex.tracing.traceID)
trace.Set(rpctracing.Sampled, true) trace.Set(rpctracing.Sampled, true)
var baseContext context.Context = ctx defer mon.Func().RemoteTrace(&ctx, monkit.NewId(), trace)(&err)
defer mon.Func().RemoteTrace(&baseContext, monkit.NewId(), trace)(&err)
ctxWrapped = &clingyWrapper{
Context: baseContext,
clx: ctx,
}
} }
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 // PromptInput gets a line of input text from the user and returns an error if
// interactive mode is disabled. // 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 { if !ex.interactive {
return "", errs.New("required user input in non-interactive setting") 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 buf []byte
var tmp [1]byte var tmp [1]byte
for { for {
_, err := ctx.Stdin().Read(tmp[:]) _, err := clingy.Stdin(ctx).Read(tmp[:])
if errors.Is(err, io.EOF) { if errors.Is(err, io.EOF) {
break break
} else if err != nil { } 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 // 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 // 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. // 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 { if !ex.interactive {
return "", errs.New("required secret input in non-interactive setting") 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 { if !ok {
return "", errs.New("unable to request secret from stdin") return "", errs.New("unable to request secret from stdin")
} }
fd := int(fh.Fd()) fd := int(fh.Fd())
for { for {
fmt.Fprint(ctx.Stdout(), prompt, " ") fmt.Fprint(clingy.Stdout(ctx), prompt, " ")
first, err := term.ReadPassword(fd) first, err := term.ReadPassword(fd)
if err != nil { if err != nil {
return "", errs.New("unable to request secret from stdin: %w", err) 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) second, err := term.ReadPassword(fd)
if err != nil { if err != nil {
return "", errs.New("unable to request secret from stdin: %w", err) 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) { if string(first) != string(second) {
fmt.Fprintln(ctx.Stdout(), "Values did not match. Try again.") fmt.Fprintln(clingy.Stdout(ctx), "Values did not match. Try again.")
fmt.Fprintln(ctx.Stdout()) fmt.Fprintln(clingy.Stdout(ctx))
continue continue
} }

View File

@ -164,7 +164,7 @@ func (ex *external) RequestAccess(ctx context.Context, satelliteAddr, apiKey, pa
return access, nil 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() serialized, err := access.Serialize()
if err != nil { if err != nil {
return errs.Wrap(err) return errs.Wrap(err)
@ -192,6 +192,6 @@ func (ex *external) ExportAccess(ctx clingy.Context, access *uplink.Access, file
return errs.Wrap(err) return errs.Wrap(err)
} }
fmt.Fprintln(ctx, "Exported access to:", filename) fmt.Fprintln(clingy.Stdout(ctx), "Exported access to:", filename)
return nil return nil
} }

View File

@ -4,15 +4,15 @@
package main package main
import ( import (
"context"
"strings" "strings"
"github.com/zeebo/clingy"
"github.com/zeebo/errs" "github.com/zeebo/errs"
"storj.io/storj/cmd/uplink/ulext" "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 `+ answer, err := ex.PromptInput(ctx, `With your permission, Storj can `+
`automatically collect analytics information from your uplink CLI to `+ `automatically collect analytics information from your uplink CLI to `+
`help improve the quality and performance of our products. This `+ `help improve the quality and performance of our products. This `+

View File

@ -13,7 +13,6 @@ import (
"net/http" "net/http"
"time" "time"
"github.com/zeebo/clingy"
"github.com/zeebo/errs" "github.com/zeebo/errs"
"storj.io/common/rpc/rpcpool" "storj.io/common/rpc/rpcpool"
@ -32,13 +31,13 @@ type External interface {
GetAccessInfo(required bool) (string, map[string]string, error) GetAccessInfo(required bool) (string, map[string]string, error)
SaveAccessInfo(defaultName string, accesses map[string]string) error SaveAccessInfo(defaultName string, accesses map[string]string) error
RequestAccess(ctx context.Context, satelliteAddress, apiKey, passphrase string) (*uplink.Access, 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 ConfigFile() string
SaveConfig(values map[string]string) error SaveConfig(values map[string]string) error
PromptInput(ctx clingy.Context, prompt string) (input string, err error) PromptInput(ctx context.Context, prompt string) (input string, err error)
PromptSecret(ctx clingy.Context, prompt string) (secret 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. // Options contains all of the possible options for opening a filesystem or project.

View File

@ -8,8 +8,6 @@ import (
"io" "io"
"time" "time"
"github.com/zeebo/clingy"
"storj.io/storj/cmd/uplink/ulloc" "storj.io/storj/cmd/uplink/ulloc"
"storj.io/uplink" "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. // Filesystem represents either the local filesystem or the data backed by a project.
type Filesystem interface { type Filesystem interface {
Close() error Close() error
Open(ctx clingy.Context, loc ulloc.Location) (MultiReadHandle, error) Open(ctx context.Context, loc ulloc.Location) (MultiReadHandle, error)
Create(ctx clingy.Context, loc ulloc.Location, opts *CreateOptions) (MultiWriteHandle, error) Create(ctx context.Context, loc ulloc.Location, opts *CreateOptions) (MultiWriteHandle, error)
Move(ctx clingy.Context, source, dest ulloc.Location) error Move(ctx context.Context, source, dest ulloc.Location) error
Copy(ctx clingy.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 Remove(ctx context.Context, loc ulloc.Location, opts *RemoveOptions) error
List(ctx context.Context, prefix ulloc.Location, opts *ListOptions) (ObjectIterator, error) List(ctx context.Context, prefix ulloc.Location, opts *ListOptions) (ObjectIterator, error)
IsLocalDir(ctx context.Context, loc ulloc.Location) bool IsLocalDir(ctx context.Context, loc ulloc.Location) bool

View File

@ -32,27 +32,27 @@ func (m *Mixed) Close() error {
} }
// Open returns a MultiReadHandle to either a local file, remote object, or stdin. // 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 { if bucket, key, ok := loc.RemoteParts(); ok {
return m.remote.Open(ctx, bucket, key) return m.remote.Open(ctx, bucket, key)
} else if path, ok := loc.LocalParts(); ok { } else if path, ok := loc.LocalParts(); ok {
return m.local.Open(ctx, path) 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. // 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 { if bucket, key, ok := loc.RemoteParts(); ok {
return m.remote.Create(ctx, bucket, key, opts) return m.remote.Create(ctx, bucket, key, opts)
} else if path, ok := loc.LocalParts(); ok { } else if path, ok := loc.LocalParts(); ok {
return m.local.Create(ctx, path) 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. // 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 oldbucket, oldkey, ok := source.RemoteParts(); ok {
if newbucket, newkey, ok := dest.RemoteParts(); ok { if newbucket, newkey, ok := dest.RemoteParts(); ok {
return m.remote.Move(ctx, oldbucket, oldkey, newbucket, newkey) 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. // 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 oldbucket, oldkey, ok := source.RemoteParts(); ok {
if newbucket, newkey, ok := dest.RemoteParts(); ok { if newbucket, newkey, ok := dest.RemoteParts(); ok {
return m.remote.Copy(ctx, oldbucket, oldkey, newbucket, newkey) return m.remote.Copy(ctx, oldbucket, oldkey, newbucket, newkey)

View File

@ -82,7 +82,7 @@ func (st State) Run(t *testing.T, args ...string) Result {
Stdout: &stdout, Stdout: &stdout,
Stderr: &stderr, 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 { for _, opt := range st.opts {
opt.fn(t, ctx, cs) opt.fn(t, ctx, cs)
} }
@ -164,26 +164,26 @@ type callbackState struct {
// ExecuteOption allows one to control the environment that a command executes in. // ExecuteOption allows one to control the environment that a command executes in.
type ExecuteOption struct { 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. // 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 { func WithFilesystem(cb func(t *testing.T, ctx context.Context, fs ulfs.Filesystem)) ExecuteOption {
return ExecuteOption{func(t *testing.T, ctx clingy.Context, cs *callbackState) { return ExecuteOption{func(t *testing.T, ctx context.Context, cs *callbackState) {
cb(t, ctx, cs.fs) cb(t, ctx, cs.fs)
}} }}
} }
// WithBucket ensures the bucket exists. // WithBucket ensures the bucket exists.
func WithBucket(name string) ExecuteOption { 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) cs.rfs.ensureBucket(name)
}} }}
} }
// WithStdin sets the command to execute with the provided string as standard input. // WithStdin sets the command to execute with the provided string as standard input.
func WithStdin(stdin string) ExecuteOption { 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 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. // WithFile sets the command to execute with a file created at the given location.
func WithFile(location string, contents ...string) ExecuteOption { func WithFile(location string, contents ...string) ExecuteOption {
contents = append([]string(nil), contents...) 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) loc, err := ulloc.Parse(location)
require.NoError(t, err) 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 // WithPendingFile sets the command to execute with a pending upload happening to
// the provided location. // the provided location.
func WithPendingFile(location string) ExecuteOption { 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) loc, err := ulloc.Parse(location)
require.NoError(t, err) require.NoError(t, err)

2
go.mod
View File

@ -36,7 +36,7 @@ require (
github.com/stripe/stripe-go/v72 v72.51.0 github.com/stripe/stripe-go/v72 v72.51.0
github.com/vivint/infectious v0.0.0-20200605153912-25a574ae18a3 github.com/vivint/infectious v0.0.0-20200605153912-25a574ae18a3
github.com/zeebo/assert v1.3.0 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/errs v1.3.0
github.com/zeebo/ini v0.0.0-20210331155437-86af75b4f524 github.com/zeebo/ini v0.0.0-20210331155437-86af75b4f524
go.etcd.io/bbolt v1.3.5 go.etcd.io/bbolt v1.3.5

4
go.sum
View File

@ -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/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 h1:TFoLXsjeXqRNFxSbk35Dk4YtszE/MQQGK10BH4ptoTg=
github.com/zeebo/blake3 v0.2.3/go.mod h1:mjJjZpnsyIVtVgTOSpJ9vmRE4wgDeyt2HU3qXvvKCaQ= 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-20220825183239-b8a4c2e29e63 h1:Fd4fMKAn1N0ko1YCW+kYmd+EM8AdYxNRYMYGNuV+ijM=
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.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.2.2/go.mod h1:sgbWHsvVuTPHcqJJGQ1WhI5KbWlHYz+2+2C/LSEtCw4=
github.com/zeebo/errs v1.3.0 h1:hmiaKqgYZzcVgRL1Vkc1Mn2914BbzB0IBxs+ebeutGs= github.com/zeebo/errs v1.3.0 h1:hmiaKqgYZzcVgRL1Vkc1Mn2914BbzB0IBxs+ebeutGs=

View File

@ -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/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 h1:TFoLXsjeXqRNFxSbk35Dk4YtszE/MQQGK10BH4ptoTg=
github.com/zeebo/blake3 v0.2.3/go.mod h1:mjJjZpnsyIVtVgTOSpJ9vmRE4wgDeyt2HU3qXvvKCaQ= 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.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.2.2/go.mod h1:sgbWHsvVuTPHcqJJGQ1WhI5KbWlHYz+2+2C/LSEtCw4=
github.com/zeebo/errs v1.3.0 h1:hmiaKqgYZzcVgRL1Vkc1Mn2914BbzB0IBxs+ebeutGs= github.com/zeebo/errs v1.3.0 h1:hmiaKqgYZzcVgRL1Vkc1Mn2914BbzB0IBxs+ebeutGs=

View File

@ -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/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 h1:TFoLXsjeXqRNFxSbk35Dk4YtszE/MQQGK10BH4ptoTg=
github.com/zeebo/blake3 v0.2.3/go.mod h1:mjJjZpnsyIVtVgTOSpJ9vmRE4wgDeyt2HU3qXvvKCaQ= 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.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.2.2/go.mod h1:sgbWHsvVuTPHcqJJGQ1WhI5KbWlHYz+2+2C/LSEtCw4=
github.com/zeebo/errs v1.3.0 h1:hmiaKqgYZzcVgRL1Vkc1Mn2914BbzB0IBxs+ebeutGs= github.com/zeebo/errs v1.3.0 h1:hmiaKqgYZzcVgRL1Vkc1Mn2914BbzB0IBxs+ebeutGs=