cmd/uplinkng: update clingy for better boolean support

this allows commands like

    uplinkng cp -r sj://foo sj://bar

to work correctly, rather than complain that sj://foo is
not a boolean.

Change-Id: I003e47aabb85566bc2b454851cf55043b17ee7ea
This commit is contained in:
Jeff Wendling 2021-12-09 14:21:52 -05:00 committed by Egon Elbre
parent e6aa52cd6b
commit 9615bd191f
15 changed files with 43 additions and 38 deletions

View File

@ -39,7 +39,7 @@ func (am *accessMaker) Setup(params clingy.Parameters, ex ulext.External, saveKi
if saveKind != amSaveForced {
am.save = params.Flag("save", "Save the access", saveKind == amSaveDefaultTrue,
clingy.Transform(strconv.ParseBool),
clingy.Transform(strconv.ParseBool), clingy.Boolean,
).(bool)
am.name = params.Flag("name", "Name to save the access value under, if --save is true", "").(string)
@ -49,11 +49,11 @@ func (am *accessMaker) Setup(params clingy.Parameters, ex ulext.External, saveKi
am.force = params.Flag("force", "Force overwrite an existing saved access", false,
clingy.Short('f'),
clingy.Transform(strconv.ParseBool),
clingy.Transform(strconv.ParseBool), clingy.Boolean,
).(bool)
am.use = params.Flag("use", "Switch the access to be the default", false,
clingy.Transform(strconv.ParseBool),
clingy.Transform(strconv.ParseBool), clingy.Boolean,
).(bool)
if saveKind != amSaveForced {

View File

@ -39,18 +39,18 @@ func (ap *accessPermissions) Setup(params clingy.Parameters) {
).([]uplink.SharePrefix)
ap.readonly = params.Flag("readonly", "Implies --disallow-writes and --disallow-deletes", true,
clingy.Transform(strconv.ParseBool)).(bool)
clingy.Transform(strconv.ParseBool), clingy.Boolean).(bool)
ap.writeonly = params.Flag("writeonly", "Implies --disallow-reads and --disallow-lists", false,
clingy.Transform(strconv.ParseBool)).(bool)
clingy.Transform(strconv.ParseBool), clingy.Boolean).(bool)
ap.disallowDeletes = params.Flag("disallow-deletes", "Disallow deletes with the access", false,
clingy.Transform(strconv.ParseBool)).(bool)
clingy.Transform(strconv.ParseBool), clingy.Boolean).(bool)
ap.disallowLists = params.Flag("disallow-lists", "Disallow lists with the access", false,
clingy.Transform(strconv.ParseBool)).(bool)
clingy.Transform(strconv.ParseBool), clingy.Boolean).(bool)
ap.disallowReads = params.Flag("disallow-reads", "Disallow reasd with the access", false,
clingy.Transform(strconv.ParseBool)).(bool)
clingy.Transform(strconv.ParseBool), clingy.Boolean).(bool)
ap.disallowWrites = params.Flag("disallow-writes", "Disallow writes with the access", false,
clingy.Transform(strconv.ParseBool)).(bool)
clingy.Transform(strconv.ParseBool), clingy.Boolean).(bool)
now := time.Now()
transformHumanDate := clingy.Transform(func(date string) (time.Time, error) {

View File

@ -27,7 +27,7 @@ func newCmdAccessList(ex ulext.External) *cmdAccessList {
func (c *cmdAccessList) Setup(params clingy.Parameters) {
c.verbose = params.Flag("verbose", "Verbose output of accesses", false,
clingy.Short('v'),
clingy.Transform(strconv.ParseBool),
clingy.Transform(strconv.ParseBool), clingy.Boolean,
).(bool)
}

View File

@ -48,7 +48,7 @@ func (c *cmdCp) Setup(params clingy.Parameters) {
c.access = params.Flag("access", "Access name or value to use", "").(string)
c.recursive = params.Flag("recursive", "Peform a recursive copy", false,
clingy.Short('r'),
clingy.Transform(strconv.ParseBool),
clingy.Transform(strconv.ParseBool), clingy.Boolean,
).(bool)
c.parallelism = params.Flag("parallelism", "Controls how many uploads/downloads to perform in parallel", 1,
clingy.Short('p'),
@ -60,11 +60,11 @@ func (c *cmdCp) Setup(params clingy.Parameters) {
return n, nil
}),
).(int)
c.dryrun = params.Flag("dryrun", "Print what operations would happen but don't execute them", false,
clingy.Transform(strconv.ParseBool),
c.dryrun = params.Flag("dry-run", "Print what operations would happen but don't execute them", false,
clingy.Transform(strconv.ParseBool), clingy.Boolean,
).(bool)
c.progress = params.Flag("progress", "Show a progress bar when possible", true,
clingy.Transform(strconv.ParseBool),
clingy.Transform(strconv.ParseBool), clingy.Boolean,
).(bool)
c.byteRange = params.Flag("range", "Downloads the specified range bytes of an object. For more information about the HTTP Range header, see https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35", "").(string)

View File

@ -36,20 +36,20 @@ func (c *cmdLs) Setup(params clingy.Parameters) {
c.access = params.Flag("access", "Access name or value to use", "").(string)
c.recursive = params.Flag("recursive", "List recursively", false,
clingy.Short('r'),
clingy.Transform(strconv.ParseBool),
clingy.Transform(strconv.ParseBool), clingy.Boolean,
).(bool)
c.encrypted = params.Flag("encrypted", "Shows keys base64 encoded without decrypting", false,
clingy.Transform(strconv.ParseBool),
clingy.Transform(strconv.ParseBool), clingy.Boolean,
).(bool)
c.pending = params.Flag("pending", "List pending object uploads instead", false,
clingy.Transform(strconv.ParseBool),
clingy.Transform(strconv.ParseBool), clingy.Boolean,
).(bool)
c.expanded = params.Flag("expanded", "Use expanded output, showing object expiration times and whether there is custom metadata attached", false,
clingy.Short('x'),
clingy.Transform(strconv.ParseBool),
clingy.Transform(strconv.ParseBool), clingy.Boolean,
).(bool)
c.utc = params.Flag("utc", "Show all timestamps in UTC instead of local time", false,
clingy.Transform(strconv.ParseBool),
clingy.Transform(strconv.ParseBool), clingy.Boolean,
).(bool)
c.prefix = params.Arg("prefix", "Prefix to list (sj://BUCKET[/KEY])", clingy.Optional,

View File

@ -32,7 +32,7 @@ func newCmdMetaGet(ex ulext.External) *cmdMetaGet {
func (c *cmdMetaGet) Setup(params clingy.Parameters) {
c.access = params.Flag("access", "Access name or value to use", "").(string)
c.encrypted = params.Flag("encrypted", "Shows keys base64 encoded without decrypting", false,
clingy.Transform(strconv.ParseBool),
clingy.Transform(strconv.ParseBool), clingy.Boolean,
).(bool)
c.location = params.Arg("location", "Location of object (sj://BUCKET/KEY)",

View File

@ -39,7 +39,7 @@ func (c *cmdMv) Setup(params clingy.Parameters) {
c.access = params.Flag("access", "Access name or value to use", "").(string)
c.recursive = params.Flag("recursive", "Move all objects or files under the specified prefix or directory", false,
clingy.Short('r'),
clingy.Transform(strconv.ParseBool),
clingy.Transform(strconv.ParseBool), clingy.Boolean,
).(bool)
c.parallelism = params.Flag("parallelism", "Controls how many objects will be moved in parallel", 1,
clingy.Short('p'),
@ -52,10 +52,10 @@ func (c *cmdMv) Setup(params clingy.Parameters) {
}),
).(int)
c.dryrun = params.Flag("dryrun", "Print what operations would happen but don't execute them", false,
clingy.Transform(strconv.ParseBool),
clingy.Transform(strconv.ParseBool), clingy.Boolean,
).(bool)
c.progress = params.Flag("progress", "Show a progress bar when possible", true,
clingy.Transform(strconv.ParseBool),
clingy.Transform(strconv.ParseBool), clingy.Boolean,
).(bool)
c.source = params.Arg("source", "Source to move", clingy.Transform(ulloc.Parse)).(ulloc.Location)

View File

@ -30,7 +30,7 @@ func newCmdRb(ex ulext.External) *cmdRb {
func (c *cmdRb) Setup(params clingy.Parameters) {
c.access = params.Flag("access", "Access name or value to use", "").(string)
c.force = params.Flag("force", "Deletes any objects in bucket first", false,
clingy.Transform(strconv.ParseBool),
clingy.Transform(strconv.ParseBool), clingy.Boolean,
).(bool)
c.loc = params.Arg("name", "Bucket name (sj://BUCKET)",

View File

@ -38,7 +38,7 @@ func (c *cmdRm) Setup(params clingy.Parameters) {
c.access = params.Flag("access", "Access name or value to use", "").(string)
c.recursive = params.Flag("recursive", "Remove recursively", false,
clingy.Short('r'),
clingy.Transform(strconv.ParseBool),
clingy.Transform(strconv.ParseBool), clingy.Boolean,
).(bool)
c.parallelism = params.Flag("parallelism", "Controls how many uploads/downloads to perform in parallel", 1,
clingy.Short('p'),
@ -51,10 +51,10 @@ func (c *cmdRm) Setup(params clingy.Parameters) {
}),
).(int)
c.encrypted = params.Flag("encrypted", "Interprets keys base64 encoded without decrypting", false,
clingy.Transform(strconv.ParseBool),
clingy.Transform(strconv.ParseBool), clingy.Boolean,
).(bool)
c.pending = params.Flag("pending", "Remove pending object uploads instead", false,
clingy.Transform(strconv.ParseBool),
clingy.Transform(strconv.ParseBool), clingy.Boolean,
).(bool)
c.location = params.Arg("location", "Location to remove (sj://BUCKET[/KEY])",

View File

@ -54,13 +54,17 @@ func (c *cmdShare) Setup(params clingy.Parameters) {
c.access = params.Flag("access", "Access name or value to share", "").(string)
c.exportTo = params.Flag("export-to", "Path to export the shared access to", "").(string)
c.baseURL = params.Flag("base-url", "The base url for link sharing", "https://link.us1.storjshare.io").(string)
c.register = params.Flag("register", "If true, creates and registers access grant", false, clingy.Transform(strconv.ParseBool)).(bool)
c.register = params.Flag("register", "If true, creates and registers access grant", false,
clingy.Transform(strconv.ParseBool), clingy.Boolean,
).(bool)
c.url = params.Flag("url", "If true, returns a url for the shared path. implies --register and --public", false,
clingy.Transform(strconv.ParseBool)).(bool)
clingy.Transform(strconv.ParseBool), clingy.Boolean,
).(bool)
c.dns = params.Flag("dns", "Specify your custom hostname. if set, returns dns settings for web hosting. implies --register and --public", "").(string)
c.authService = params.Flag("auth-service", "URL for shared auth service", "https://auth.us1.storjshare.io").(string)
c.public = params.Flag("public", "If true, the access will be public. --dns and --url override this", false,
clingy.Transform(strconv.ParseBool)).(bool)
clingy.Transform(strconv.ParseBool), clingy.Boolean,
).(bool)
c.ap.SetupWithPrefixArg(params)
}

View File

@ -28,7 +28,8 @@ 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)
clingy.Transform(strconv.ParseBool), clingy.Boolean,
).(bool)
}
func (c *cmdVersion) Execute(ctx clingy.Context) error {

View File

@ -49,7 +49,7 @@ func newExternal() *external {
func (ex *external) Setup(f clingy.Flags) {
ex.interactive = f.Flag(
"interactive", "Controls if interactive input is allowed", true,
clingy.Transform(strconv.ParseBool),
clingy.Transform(strconv.ParseBool), clingy.Boolean,
clingy.Advanced,
).(bool)

2
go.mod
View File

@ -35,7 +35,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-20211207200715-0d02f56b01b4
github.com/zeebo/clingy v0.0.0-20211209163509-9715de867439
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

@ -533,8 +533,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-20211207200715-0d02f56b01b4 h1:vvuOUO80GDLxNk+NZtdZmfdVrW4so/Exd58lpP268mU=
github.com/zeebo/clingy v0.0.0-20211207200715-0d02f56b01b4/go.mod h1:MHEhXvEfewflU7SSVKHI7nkdU+fpyxZ5XPPzj+5gYNw=
github.com/zeebo/clingy v0.0.0-20211209163509-9715de867439 h1:DuN9KPJE00D+IYD5NRYpotulqet33rHwe1djtPTc2IM=
github.com/zeebo/clingy v0.0.0-20211209163509-9715de867439/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 h1:5NFypMTuSdoySVTqlNs1dEoU21QVamMQJxW/Fii5O7g=
github.com/zeebo/errs v1.2.2/go.mod h1:sgbWHsvVuTPHcqJJGQ1WhI5KbWlHYz+2+2C/LSEtCw4=

View File

@ -45,7 +45,7 @@ uplinkng cp "$SRC_DIR/multisegment-upload-testfile" "sj://$BUCKET/" --progress=f
uplinkng cp "$SRC_DIR/diff-size-segments" "sj://$BUCKET/" --progress=false --access $STORJ_ACCESS
uplinkng access save -f --name named-access --access $STORJ_ACCESS
FILES=$(STORJ_ACCESS= uplinkng --access named-access ls "sj://$BUCKET" | tee $TMPDIR/list | wc -l)
FILES=$(STORJ_ACCESS= uplinkng ls --access named-access "sj://$BUCKET" | tee $TMPDIR/list | wc -l)
EXPECTED_FILES="5"
if [ "$FILES" == $EXPECTED_FILES ]
then
@ -73,7 +73,7 @@ uplinkng cp "sj://$BUCKET/diff-size-segments" "$DST_DIR" --progress=f
uplinkng ls "sj://$BUCKET/small-upload-testfile" --access $STORJ_ACCESS | grep "small-upload-testfile"
# test ranged download of object
uplinkng cp "sj://$BUCKET/small-upload-testfile" "$DST_DIR/file-from-cp-range" --progress=false --range bytes=0-5
uplinkng cp "sj://$BUCKET/small-upload-testfile" "$DST_DIR/file-from-cp-range" --progress=false --range bytes=0-5 --access $STORJ_ACCESS
EXPECTED_FILE_SIZE="6"
ACTUAL_FILE_SIZE=$(get_file_size "$DST_DIR/file-from-cp-range")
if [ "$EXPECTED_FILE_SIZE" != "$ACTUAL_FILE_SIZE" ]
@ -117,7 +117,7 @@ uplinkng rm "sj://$BUCKET/multisegment-upload-testfile" --access $STORJ_ACCESS
uplinkng rm "sj://$BUCKET/diff-size-segments" --access $STORJ_ACCESS
uplinkng ls "sj://$BUCKET" --access $STORJ_ACCESS
uplinkng ls -x true "sj://$BUCKET" --access $STORJ_ACCESS
uplinkng ls -x "sj://$BUCKET" --access $STORJ_ACCESS
uplinkng rb "sj://$BUCKET" --access $STORJ_ACCESS