Skip to content

Commit 426faad

Browse files
authored
fix: make w3 up --no-wrap work as advertised. (#160)
Fix and test handling of `--wrap` option to `w3 up` | flag | result | |--------------|-------------| | undefined | wrap: true | | --wrap | wrap: true | | --wrap true | wrap: true | | --wrap=true | wrap: true | | --wrap false | wrap: false | | --wrap=false | wrap: false | | --no-wrap | wrap: false | Also normalises the behaviour of other boolean flags to `w3 up` so we can set them like `w3 up --hidden=${{input.hidden}}` in scripts, where it would be fiddly to optionally include a flag. see: https://github.com/web3-storage/add-to-web3/pull/89/files#diff-1243c5424efaaa19bd8e813c5e6f6da46316e63761421b3e5f5c8ced9a36e6b6R51 License: MIT --------- Signed-off-by: Oli Evans <oli@protocol.ai>
1 parent 56793f0 commit 426faad

File tree

2 files changed

+68
-4
lines changed

2 files changed

+68
-4
lines changed

bin.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ cli
7171
.command('up <file>')
7272
.alias('upload', 'put')
7373
.describe('Store a file(s) to the service and register an upload.')
74-
.option('--no-wrap', "Don't wrap input files with a directory.", false)
75-
.option('-H, --hidden', 'Include paths that start with ".".')
74+
.option('-H, --hidden', 'Include paths that start with ".".', false)
7675
.option('-c, --car', 'File is a CAR file.', false)
77-
.option('--json', 'Format as newline delimited JSON')
78-
.option('--verbose', 'Output more details.')
76+
.option('--wrap', "Wrap single input file in a directory. Has no effect on directory or CAR uploads. Pass --no-wrap to disable.", true)
77+
.option('--json', 'Format as newline delimited JSON', false)
78+
.option('--verbose', 'Output more details.', false)
7979
.option(
8080
'--shard-size',
8181
'Shard uploads into CAR files of approximately this size in bytes.'

test/bin.spec.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,70 @@ export const testW3Up = {
620620
assert.match(up.error, /Stored 1 file/)
621621
}),
622622

623+
'w3 up --no-wrap': test(async (assert, context) => {
624+
const email = 'alice@web.mail'
625+
await login(context, { email })
626+
await selectPlan(context, { email })
627+
628+
const create = await w3
629+
.args([
630+
'space',
631+
'create',
632+
'home',
633+
'--no-recovery',
634+
'--no-account',
635+
'--customer',
636+
email,
637+
])
638+
.env(context.env.alice)
639+
.join()
640+
641+
assert.ok(create.status.success())
642+
643+
const up = await w3
644+
.args(['up', 'test/fixtures/pinpie.jpg', '--no-wrap'])
645+
.env(context.env.alice)
646+
.join()
647+
648+
assert.match(
649+
up.output,
650+
/bafkreiajkbmpugz75eg2tmocmp3e33sg5kuyq2amzngslahgn6ltmqxxfa/
651+
)
652+
assert.match(up.error, /Stored 1 file/)
653+
}),
654+
655+
'w3 up --wrap false': test(async (assert, context) => {
656+
const email = 'alice@web.mail'
657+
await login(context, { email })
658+
await selectPlan(context, { email })
659+
660+
const create = await w3
661+
.args([
662+
'space',
663+
'create',
664+
'home',
665+
'--no-recovery',
666+
'--no-account',
667+
'--customer',
668+
email,
669+
])
670+
.env(context.env.alice)
671+
.join()
672+
673+
assert.ok(create.status.success())
674+
675+
const up = await w3
676+
.args(['up', 'test/fixtures/pinpie.jpg', '--wrap', 'false'])
677+
.env(context.env.alice)
678+
.join()
679+
680+
assert.match(
681+
up.output,
682+
/bafkreiajkbmpugz75eg2tmocmp3e33sg5kuyq2amzngslahgn6ltmqxxfa/
683+
)
684+
assert.match(up.error, /Stored 1 file/)
685+
}),
686+
623687
'w3 up --car': test(async (assert, context) => {
624688
const email = 'alice@web.mail'
625689
await login(context, { email })

0 commit comments

Comments
 (0)