Skip to content

Commit

Permalink
fix(upload): handle glob expansion by shell
Browse files Browse the repository at this point in the history
fixes #105

When a glob character is used in the source argument _and_ it matches
more than one file or folder no action will be performed and an
actionable error message is displayed instead.
  • Loading branch information
line-o committed Oct 12, 2023
1 parent 6a39c38 commit eb4c10f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
17 changes: 16 additions & 1 deletion commands/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,19 @@ async function uploadFileOrFolder (db, source, target, options) {
return 0
}

export const command = ['upload [options] <source> <target>', 'up']
export const command = ['upload <source> <target>', 'up']
export const describe = 'Upload files and directories'

export function builder (yargs) {
yargs
.positional('target', {
type: 'string',
normalize: false
})
.positional('source', {
type: 'string',
normalize: true
})
.option('i', {
alias: 'include',
describe: 'Include only files matching one or more of include patterns (comma separated)',
Expand Down Expand Up @@ -264,12 +272,19 @@ export function builder (yargs) {
type: 'boolean'
})
.nargs({ i: 1, e: 1 })
// .demandCommand(0)
// .strict(true)
}

export async function handler (argv) {
if (argv.help) {
return 0
}

if (argv._.length > 1) {
throw Error('More than two positional arguments provided.\nDid you use a globbing character, like * or ? for the source argument?\nUse --include and/or --exclude instead.')
}

const { threads, mintime, source, target } = argv

if (typeof mintime !== 'number' || mintime < 0) {
Expand Down
2 changes: 1 addition & 1 deletion spec/tests/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,8 @@ test('with fixtures uploaded', async (t) => {
/db/list-test/fixtures/test.xml
/db/list-test/tests
/db/list-test/tests/cli.js
/db/list-test/tests/upload.js
/db/list-test/tests/info.js
/db/list-test/tests/upload.js
/db/list-test/tests/configuration.js
/db/list-test/tests/exec.js
/db/list-test/tests/rm.js
Expand Down
7 changes: 7 additions & 0 deletions spec/tests/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ test('upload dotfile', async (t) => {
t.end()
})

test('error on upload with more than two positional arguments', async (t) => {
const { stderr, stdout } = await run('xst', ['up', 'spec/fixtures/test-app.xar', 'spec/fixtures/test-lib.xar', '/db/tmp'], asAdmin)
t.notOk(stdout, stdout)
t.equal(stderr, 'More than two positional arguments provided.\nDid you use a globbing character, like * or ? for the source argument?\nUse --include and/or --exclude instead.\n')
t.end()
})

test.skip("calling 'xst up modules/test.xq /db/foo' as guest", async (t) => {
const { stderr, stdout } = await run('xst', ['up', 'modules', '/db/foo'])
if (stdout) t.fail(stdout)
Expand Down

0 comments on commit eb4c10f

Please sign in to comment.