From 7b7b879db1a6e4a5f6250a98777670d56f3eb04d Mon Sep 17 00:00:00 2001 From: Juri Leino Date: Sun, 8 Oct 2023 18:03:39 +0200 Subject: [PATCH] fix(upload): handle glob expansion by shell 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. --- commands/upload.js | 17 ++++++++++++++++- spec/tests/list.js | 2 +- spec/tests/upload.js | 7 +++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/commands/upload.js b/commands/upload.js index b823d30..526e839 100755 --- a/commands/upload.js +++ b/commands/upload.js @@ -211,11 +211,19 @@ async function uploadFileOrFolder (db, source, target, options) { return 0 } -export const command = ['upload [options] ', 'up'] +export const command = ['upload ', '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)', @@ -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) { diff --git a/spec/tests/list.js b/spec/tests/list.js index 52abf8d..58a7896 100644 --- a/spec/tests/list.js +++ b/spec/tests/list.js @@ -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 diff --git a/spec/tests/upload.js b/spec/tests/upload.js index 59757f6..576bc72 100644 --- a/spec/tests/upload.js +++ b/spec/tests/upload.js @@ -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)