cmd/uplinkng: update for breaking clingy changes

clingy changed some and this is just fixes for that

Change-Id: I729aed6329fe0988fcb9b4407f16966a753b3204
This commit is contained in:
Jeff Wendling 2021-05-24 19:11:50 -04:00
parent bbd3efaeed
commit f474bb6179
22 changed files with 97 additions and 97 deletions

View File

@ -27,28 +27,28 @@ type accessPermissions struct {
notAfter time.Time
}
func (ap *accessPermissions) Setup(a clingy.Arguments, f clingy.Flags) {
ap.prefixes = f.New("prefix", "Key prefix access will be restricted to", []string{},
func (ap *accessPermissions) Setup(params clingy.Parameters) {
ap.prefixes = params.Flag("prefix", "Key prefix access will be restricted to", []string{},
clingy.Repeated).([]string)
ap.readonly = f.New("readonly", "Implies --disallow-writes and --disallow-deletes", true,
ap.readonly = params.Flag("readonly", "Implies --disallow-writes and --disallow-deletes", true,
clingy.Transform(strconv.ParseBool)).(bool)
ap.writeonly = f.New("writeonly", "Implies --disallow-reads and --disallow-lists", false,
ap.writeonly = params.Flag("writeonly", "Implies --disallow-reads and --disallow-lists", false,
clingy.Transform(strconv.ParseBool)).(bool)
ap.disallowDeletes = f.New("disallow-deletes", "Disallow deletes with the access", false,
ap.disallowDeletes = params.Flag("disallow-deletes", "Disallow deletes with the access", false,
clingy.Transform(strconv.ParseBool)).(bool)
ap.disallowLists = f.New("disallow-lists", "Disallow lists with the access", false,
ap.disallowLists = params.Flag("disallow-lists", "Disallow lists with the access", false,
clingy.Transform(strconv.ParseBool)).(bool)
ap.disallowReads = f.New("disallow-reads", "Disallow reasd with the access", false,
ap.disallowReads = params.Flag("disallow-reads", "Disallow reasd with the access", false,
clingy.Transform(strconv.ParseBool)).(bool)
ap.disallowWrites = f.New("disallow-writes", "Disallow writes with the access", false,
ap.disallowWrites = params.Flag("disallow-writes", "Disallow writes with the access", false,
clingy.Transform(strconv.ParseBool)).(bool)
ap.notBefore = f.New("not-before",
ap.notBefore = params.Flag("not-before",
"Disallow access before this time (e.g. '+2h', '2020-01-02T15:04:05Z0700')",
time.Time{}, clingy.Transform(parseRelativeTime), clingy.Type("relative_time")).(time.Time)
ap.notAfter = f.New("not-after",
ap.notAfter = params.Flag("not-after",
"Disallow access after this time (e.g. '+2h', '2020-01-02T15:04:05Z0700')",
time.Time{}, clingy.Transform(parseRelativeTime), clingy.Type("relative_time")).(time.Time)
}

View File

@ -18,13 +18,13 @@ type cmdAccessCreate struct {
save bool
}
func (c *cmdAccessCreate) Setup(a clingy.Arguments, f clingy.Flags) {
c.token = f.New("token", "Setup token from satellite UI (prompted if unspecified)", "").(string)
c.passphrase = f.New("passphrase", "Passphrase used for encryption (prompted if unspecified)", "").(string)
c.name = f.New("name", "Name to save newly created access, if --save is true", "default").(string)
c.save = f.New("save", "Save the access", true, clingy.Transform(strconv.ParseBool)).(bool)
func (c *cmdAccessCreate) Setup(params clingy.Parameters) {
c.token = params.Flag("token", "Setup token from satellite UI (prompted if unspecified)", "").(string)
c.passphrase = params.Flag("passphrase", "Passphrase used for encryption (prompted if unspecified)", "").(string)
c.name = params.Flag("name", "Name to save newly created access, if --save is true", "default").(string)
c.save = params.Flag("save", "Save the access", true, clingy.Transform(strconv.ParseBool)).(bool)
c.accessPermissions.Setup(a, f)
c.accessPermissions.Setup(params)
}
func (c *cmdAccessCreate) Execute(ctx clingy.Context) error {

View File

@ -12,8 +12,8 @@ type cmdAccessDelete struct {
name string
}
func (c *cmdAccessDelete) Setup(a clingy.Arguments, f clingy.Flags) {
c.name = a.New("name", "Access to delete").(string)
func (c *cmdAccessDelete) Setup(params clingy.Parameters) {
c.name = params.Arg("name", "Access to delete").(string)
}
func (c *cmdAccessDelete) Execute(ctx clingy.Context) error {

View File

@ -17,8 +17,8 @@ type cmdAccessList struct {
verbose bool
}
func (c *cmdAccessList) Setup(a clingy.Arguments, f clingy.Flags) {
c.verbose = f.New("verbose", "Verbose output of accesses", false,
func (c *cmdAccessList) Setup(params clingy.Parameters) {
c.verbose = params.Flag("verbose", "Verbose output of accesses", false,
clingy.Short('v'),
clingy.Transform(strconv.ParseBool),
).(bool)

View File

@ -8,7 +8,7 @@ import "github.com/zeebo/clingy"
type cmdAccessRevoke struct {
}
func (c *cmdAccessRevoke) Setup(a clingy.Arguments, f clingy.Flags) {
func (c *cmdAccessRevoke) Setup(params clingy.Parameters) {
}
func (c *cmdAccessRevoke) Execute(ctx clingy.Context) error {

View File

@ -19,15 +19,15 @@ type cmdAccessSave struct {
use bool
}
func (c *cmdAccessSave) Setup(a clingy.Arguments, f clingy.Flags) {
c.access = f.New("access", "Access to save (prompted if unspecified)", "").(string)
c.name = f.New("name", "Name to save the access grant under", "default").(string)
func (c *cmdAccessSave) Setup(params clingy.Parameters) {
c.access = params.Flag("access", "Access to save (prompted if unspecified)", "").(string)
c.name = params.Flag("name", "Name to save the access grant under", "default").(string)
c.force = f.New("force", "Force overwrite an existing saved access grant", false,
c.force = params.Flag("force", "Force overwrite an existing saved access grant", false,
clingy.Short('f'),
clingy.Transform(strconv.ParseBool),
).(bool)
c.use = f.New("use", "Set the saved access to be the one used by default", false,
c.use = params.Flag("use", "Set the saved access to be the one used by default", false,
clingy.Transform(strconv.ParseBool),
).(bool)
}

View File

@ -12,8 +12,8 @@ type cmdAccessUse struct {
name string
}
func (c *cmdAccessUse) Setup(a clingy.Arguments, f clingy.Flags) {
c.name = a.New("name", "Access to use").(string)
func (c *cmdAccessUse) Setup(params clingy.Parameters) {
c.name = params.Arg("name", "Access to use").(string)
}
func (c *cmdAccessUse) Execute(ctx clingy.Context) error {

View File

@ -27,22 +27,22 @@ type cmdCp struct {
dest ulloc.Location
}
func (c *cmdCp) Setup(a clingy.Arguments, f clingy.Flags) {
c.projectProvider.Setup(a, f)
func (c *cmdCp) Setup(params clingy.Parameters) {
c.projectProvider.Setup(params)
c.recursive = f.New("recursive", "Peform a recursive copy", false,
c.recursive = params.Flag("recursive", "Peform a recursive copy", false,
clingy.Short('r'),
clingy.Transform(strconv.ParseBool),
).(bool)
c.dryrun = f.New("dryrun", "Print what operations would happen but don't execute them", false,
c.dryrun = params.Flag("dryrun", "Print what operations would happen but don't execute them", false,
clingy.Transform(strconv.ParseBool),
).(bool)
c.progress = f.New("progress", "Show a progress bar when possible", true,
c.progress = params.Flag("progress", "Show a progress bar when possible", true,
clingy.Transform(strconv.ParseBool),
).(bool)
c.source = a.New("source", "Source to copy", clingy.Transform(ulloc.Parse)).(ulloc.Location)
c.dest = a.New("dest", "Desination to copy", clingy.Transform(ulloc.Parse)).(ulloc.Location)
c.source = params.Arg("source", "Source to copy", clingy.Transform(ulloc.Parse)).(ulloc.Location)
c.dest = params.Arg("dest", "Desination to copy", clingy.Transform(ulloc.Parse)).(ulloc.Location)
}
func (c *cmdCp) Execute(ctx clingy.Context) error {

View File

@ -24,24 +24,24 @@ type cmdLs struct {
prefix *ulloc.Location
}
func (c *cmdLs) Setup(a clingy.Arguments, f clingy.Flags) {
c.projectProvider.Setup(a, f)
func (c *cmdLs) Setup(params clingy.Parameters) {
c.projectProvider.Setup(params)
c.recursive = f.New("recursive", "List recursively", false,
c.recursive = params.Flag("recursive", "List recursively", false,
clingy.Short('r'),
clingy.Transform(strconv.ParseBool),
).(bool)
c.encrypted = f.New("encrypted", "Shows keys base64 encoded without decrypting", false,
c.encrypted = params.Flag("encrypted", "Shows keys base64 encoded without decrypting", false,
clingy.Transform(strconv.ParseBool),
).(bool)
c.pending = f.New("pending", "List pending object uploads instead", false,
c.pending = params.Flag("pending", "List pending object uploads instead", false,
clingy.Transform(strconv.ParseBool),
).(bool)
c.utc = f.New("utc", "Show all timestamps in UTC instead of local time", false,
c.utc = params.Flag("utc", "Show all timestamps in UTC instead of local time", false,
clingy.Transform(strconv.ParseBool),
).(bool)
c.prefix = a.New("prefix", "Prefix to list (sj://BUCKET[/KEY])", clingy.Optional,
c.prefix = params.Arg("prefix", "Prefix to list (sj://BUCKET[/KEY])", clingy.Optional,
clingy.Transform(ulloc.Parse),
).(*ulloc.Location)
}

View File

@ -14,10 +14,10 @@ type cmdMb struct {
name string
}
func (c *cmdMb) Setup(a clingy.Arguments, f clingy.Flags) {
c.projectProvider.Setup(a, f)
func (c *cmdMb) Setup(params clingy.Parameters) {
c.projectProvider.Setup(params)
c.name = a.New("name", "Bucket name (sj://BUCKET)").(string)
c.name = params.Arg("name", "Bucket name (sj://BUCKET)").(string)
}
func (c *cmdMb) Execute(ctx clingy.Context) error {

View File

@ -23,17 +23,17 @@ type cmdMetaGet struct {
entry *string
}
func (c *cmdMetaGet) Setup(a clingy.Arguments, f clingy.Flags) {
c.projectProvider.Setup(a, f)
func (c *cmdMetaGet) Setup(params clingy.Parameters) {
c.projectProvider.Setup(params)
c.encrypted = f.New("encrypted", "Shows keys base64 encoded without decrypting", false,
c.encrypted = params.Flag("encrypted", "Shows keys base64 encoded without decrypting", false,
clingy.Transform(strconv.ParseBool),
).(bool)
c.location = a.New("location", "Location of object (sj://BUCKET/KEY)",
c.location = params.Arg("location", "Location of object (sj://BUCKET/KEY)",
clingy.Transform(ulloc.Parse),
).(ulloc.Location)
c.entry = a.New("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 {

View File

@ -21,14 +21,14 @@ type cmdRb struct {
loc ulloc.Location
}
func (c *cmdRb) Setup(a clingy.Arguments, f clingy.Flags) {
c.projectProvider.Setup(a, f)
func (c *cmdRb) Setup(params clingy.Parameters) {
c.projectProvider.Setup(params)
c.force = f.New("force", "Deletes any objects in bucket first", false,
c.force = params.Flag("force", "Deletes any objects in bucket first", false,
clingy.Transform(strconv.ParseBool),
).(bool)
c.loc = a.New("name", "Bucket name (sj://BUCKET)",
c.loc = params.Arg("name", "Bucket name (sj://BUCKET)",
clingy.Transform(ulloc.Parse),
).(ulloc.Location)
}

View File

@ -22,18 +22,18 @@ type cmdRm struct {
location ulloc.Location
}
func (c *cmdRm) Setup(a clingy.Arguments, f clingy.Flags) {
c.projectProvider.Setup(a, f)
func (c *cmdRm) Setup(params clingy.Parameters) {
c.projectProvider.Setup(params)
c.recursive = f.New("recursive", "Remove recursively", false,
c.recursive = params.Flag("recursive", "Remove recursively", false,
clingy.Short('r'),
clingy.Transform(strconv.ParseBool),
).(bool)
c.encrypted = f.New("encrypted", "Interprets keys base64 encoded without decrypting", false,
c.encrypted = params.Flag("encrypted", "Interprets keys base64 encoded without decrypting", false,
clingy.Transform(strconv.ParseBool),
).(bool)
c.location = a.New("location", "Location to remove (sj://BUCKET[/KEY])",
c.location = params.Arg("location", "Location to remove (sj://BUCKET[/KEY])",
clingy.Transform(ulloc.Parse),
).(ulloc.Location)
}

View File

@ -9,8 +9,8 @@ type cmdShare struct {
projectProvider
}
func (c *cmdShare) Setup(a clingy.Arguments, f clingy.Flags) {
c.projectProvider.Setup(a, f)
func (c *cmdShare) Setup(params clingy.Parameters) {
c.projectProvider.Setup(params)
}
func (c *cmdShare) Execute(ctx clingy.Context) error {

View File

@ -16,8 +16,8 @@ type cmdVersion struct {
verbose bool
}
func (c *cmdVersion) Setup(a clingy.Arguments, f clingy.Flags) {
c.verbose = f.New(
func (c *cmdVersion) Setup(params clingy.Parameters) {
c.verbose = params.Flag(
"verbose", "prints all dependency versions", false,
clingy.Short('v'),
clingy.Transform(strconv.ParseBool)).(bool)

View File

@ -37,18 +37,18 @@ func newGlobalFlags() *globalFlags {
}
func (g *globalFlags) Setup(f clingy.Flags) {
g.interactive = f.New(
g.interactive = f.Flag(
"interactive", "Controls if interactive input is allowed", true,
clingy.Transform(strconv.ParseBool),
clingy.Advanced,
).(bool)
g.configDir = f.New(
g.configDir = f.Flag(
"config-dir", "Directory that stores the configuration",
appDir(false, "storj", "uplink"),
).(string)
g.oldConfigDir = f.New(
g.oldConfigDir = f.Flag(
"old-config-dir", "Directory that stores legacy configuration. Only used during migration",
appDir(true, "storj", "uplink"),
clingy.Advanced,
@ -194,7 +194,7 @@ func (g *globalFlags) SaveAccessInfo(accessDefault string, accesses map[string]s
return nil
}
func (g *globalFlags) Wrap(ctx clingy.Context, cmd clingy.Cmd) error {
func (g *globalFlags) Wrap(ctx clingy.Context, cmd clingy.Command) error {
if err := g.migrate(); err != nil {
return err
}

View File

@ -21,13 +21,13 @@ func main() {
Dynamic: gf.Dynamic,
Wrap: gf.Wrap,
}.Run(context.Background(), func(c clingy.Commands, f clingy.Flags) {
}.Run(context.Background(), func(cmds clingy.Commands) {
// setup the dynamic global flags first so that they may be consulted
// by the stdlib flags during their definition.
gf.Setup(f)
newStdlibFlags(flag.CommandLine).Setup(f)
gf.Setup(cmds)
newStdlibFlags(flag.CommandLine).Setup(cmds)
commands(c, f)
commands(cmds)
})
if err != nil {
fmt.Fprintf(os.Stderr, "%+v\n", err)
@ -37,23 +37,23 @@ func main() {
}
}
func commands(c clingy.Commands, f clingy.Flags) {
c.Group("access", "Access related commands", func() {
c.New("save", "Save an existing access", new(cmdAccessSave))
c.New("create", "Create an access from a setup token", new(cmdAccessCreate))
c.New("delete", "Delete an access from local store", new(cmdAccessDelete))
c.New("list", "List saved accesses", new(cmdAccessList))
c.New("use", "Set default access to use", new(cmdAccessUse))
c.New("revoke", "Revoke an access", new(cmdAccessRevoke))
func commands(cmds clingy.Commands) {
cmds.Group("access", "Access related commands", func() {
cmds.New("save", "Save an existing access", new(cmdAccessSave))
cmds.New("create", "Create an access from a setup token", new(cmdAccessCreate))
cmds.New("delete", "Delete an access from local store", new(cmdAccessDelete))
cmds.New("list", "List saved accesses", new(cmdAccessList))
cmds.New("use", "Set default access to use", new(cmdAccessUse))
cmds.New("revoke", "Revoke an access", new(cmdAccessRevoke))
})
c.New("share", "Shares restricted accesses to objects", new(cmdShare))
c.New("mb", "Create a new bucket", new(cmdMb))
c.New("rb", "Remove a bucket bucket", new(cmdRb))
c.New("cp", "Copies files or objects into or out of tardigrade", new(cmdCp))
c.New("ls", "Lists buckets, prefixes, or objects", new(cmdLs))
c.New("rm", "Remove an object", new(cmdRm))
c.Group("meta", "Object metadata related commands", func() {
c.New("get", "Get an object's metadata", new(cmdMetaGet))
cmds.New("share", "Shares restricted accesses to objects", new(cmdShare))
cmds.New("mb", "Create a new bucket", new(cmdMb))
cmds.New("rb", "Remove a bucket bucket", new(cmdRb))
cmds.New("cp", "Copies files or objects into or out of tardigrade", new(cmdCp))
cmds.New("ls", "Lists buckets, prefixes, or objects", new(cmdLs))
cmds.New("rm", "Remove an object", new(cmdRm))
cmds.Group("meta", "Object metadata related commands", func() {
cmds.New("get", "Get an object's metadata", new(cmdMetaGet))
})
c.New("version", "Prints version information", new(cmdVersion))
cmds.New("version", "Prints version information", new(cmdVersion))
}

View File

@ -20,8 +20,8 @@ type projectProvider struct {
testFilesystem ulfs.Filesystem
}
func (pp *projectProvider) Setup(a clingy.Arguments, f clingy.Flags) {
pp.access = f.New("access", "Which access to use", "").(string)
func (pp *projectProvider) Setup(params clingy.Parameters) {
pp.access = params.Flag("access", "Which access to use", "").(string)
}
func (pp *projectProvider) SetTestFilesystem(fs ulfs.Filesystem) { pp.testFilesystem = fs }

View File

@ -25,7 +25,7 @@ func (s *stdlibFlags) Setup(f clingy.Flags) {
// the expected clingy pipeline.
s.fs.VisitAll(func(fl *flag.Flag) {
name, _ := flag.UnquoteUsage(fl)
f.New(fl.Name, fl.Usage, fl.DefValue,
f.Flag(fl.Name, fl.Usage, fl.DefValue,
clingy.Advanced,
clingy.Type(name),
clingy.Transform(func(val string) (string, error) {

View File

@ -17,7 +17,7 @@ import (
// Setup returns some State that can be run multiple times with different command
// line arguments.
func Setup(cmds func(clingy.Commands, clingy.Flags), opts ...ExecuteOption) State {
func Setup(cmds func(clingy.Commands), opts ...ExecuteOption) State {
return State{
cmds: cmds,
opts: opts,
@ -26,7 +26,7 @@ func Setup(cmds func(clingy.Commands, clingy.Flags), opts ...ExecuteOption) Stat
// State represents some state and environment for a command to execute in.
type State struct {
cmds func(clingy.Commands, clingy.Flags)
cmds func(clingy.Commands)
opts []ExecuteOption
}
@ -68,7 +68,7 @@ func (st State) Run(t *testing.T, args ...string) Result {
Stdout: &stdout,
Stderr: &stderr,
Wrap: func(ctx clingy.Context, cmd clingy.Cmd) error {
Wrap: func(ctx clingy.Context, cmd clingy.Command) error {
for _, opt := range st.opts {
opt.fn(t, ctx, tfs)
}

2
go.mod
View File

@ -40,7 +40,7 @@ require (
github.com/vivint/infectious v0.0.0-20200605153912-25a574ae18a3
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c // indirect
github.com/zeebo/assert v1.3.0
github.com/zeebo/clingy v0.0.0-20210406153335-0504f579bda1
github.com/zeebo/clingy v0.0.0-20210622223751-00a909f86ea9
github.com/zeebo/errs v1.2.2
github.com/zeebo/ini v0.0.0-20210331155437-86af75b4f524
go.etcd.io/bbolt v1.3.5

4
go.sum
View File

@ -534,8 +534,8 @@ github.com/zeebo/assert v0.0.0-20181109011804-10f827ce2ed6/go.mod h1:yssERNPivll
github.com/zeebo/assert v1.1.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0=
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/clingy v0.0.0-20210406153335-0504f579bda1 h1:fxciFdO44MX0vCX58l+BQUi3jXw5CJu4uytNwvmS9r4=
github.com/zeebo/clingy v0.0.0-20210406153335-0504f579bda1/go.mod h1:8+xc/32PGdlAA4nzjz2Bgb3Rf/LAN8/KGrXxIfnlPmw=
github.com/zeebo/clingy v0.0.0-20210622223751-00a909f86ea9 h1:bBOSzs7lrWUkayGlmuAfHM4dpPpAzGfSS77lMOVR2qE=
github.com/zeebo/clingy v0.0.0-20210622223751-00a909f86ea9/go.mod h1:8+xc/32PGdlAA4nzjz2Bgb3Rf/LAN8/KGrXxIfnlPmw=
github.com/zeebo/errs v1.1.1/go.mod h1:Yj8dHrUQwls1bF3dr/vcSIu+qf4mI7idnTcHfoACc6I=
github.com/zeebo/errs v1.2.2 h1:5NFypMTuSdoySVTqlNs1dEoU21QVamMQJxW/Fii5O7g=
github.com/zeebo/errs v1.2.2/go.mod h1:sgbWHsvVuTPHcqJJGQ1WhI5KbWlHYz+2+2C/LSEtCw4=