diff --git a/packages/core/strapi/bin/strapi.js b/packages/core/strapi/bin/strapi.js index c370e0eede..c2f33cabfc 100755 --- a/packages/core/strapi/bin/strapi.js +++ b/packages/core/strapi/bin/strapi.js @@ -296,6 +296,14 @@ program .addOption(excludeOption) .addOption(onlyOption) .hook('preAction', validateExcludeOnly) + .hook( + 'preAction', + ifOptions( + (opts) => !(opts.from || opts.to) || (opts.from && opts.to), + () => + exitWith(1, 'Exactly one remote source (from) or destination (to) option must be provided') + ) + ) // If --from is used, validate the URL and token .hook( 'preAction', @@ -346,21 +354,6 @@ program } ) ) - .hook( - 'preAction', - ifOptions( - (opts) => !opts.from && !opts.to, - () => - exitWith(1, 'At least one remote source (from) or destination (to) option must be provided') - ) - ) - .hook( - 'preAction', - ifOptions( - (opts) => opts.from && opts.to, - () => exitWith(1, 'Only one source (from) or destination (to) option may be provided') - ) - ) .action(getLocalScript('transfer/transfer')); // `$ strapi export` diff --git a/packages/core/strapi/lib/commands/__tests__/data-transfer/transfer.test.js b/packages/core/strapi/lib/commands/__tests__/data-transfer/transfer.test.js index a117642f06..2ce6a78722 100644 --- a/packages/core/strapi/lib/commands/__tests__/data-transfer/transfer.test.js +++ b/packages/core/strapi/lib/commands/__tests__/data-transfer/transfer.test.js @@ -35,6 +35,9 @@ describe('Transfer', () => { strapi: { providers: { createLocalStrapiSourceProvider: jest.fn().mockReturnValue({ name: 'testLocalSource' }), + createLocalStrapiDestinationProvider: jest + .fn() + .mockReturnValue({ name: 'testLocalDestination' }), createRemoteStrapiDestinationProvider: jest .fn() .mockReturnValue({ name: 'testRemoteDest' }), diff --git a/packages/core/strapi/lib/commands/transfer/transfer.js b/packages/core/strapi/lib/commands/transfer/transfer.js index a13047af28..3e92fb2b24 100644 --- a/packages/core/strapi/lib/commands/transfer/transfer.js +++ b/packages/core/strapi/lib/commands/transfer/transfer.js @@ -44,8 +44,13 @@ module.exports = async (opts) => { exitWith(1, 'Could not parse command arguments'); } - const strapi = await createStrapiInstance(); + if (!(opts.from || opts.to) || (opts.from && opts.to)) { + console.log('from', opts.from); + console.log('to', opts.to); + exitWith(1, 'Exactly one source (from) or destination (to) option must be provided'); + } + const strapi = await createStrapiInstance(); let source; let destination;