fix option validation and order

This commit is contained in:
Ben Irvin 2023-03-08 10:35:07 +01:00
parent e404bc6015
commit ac4e688995
3 changed files with 17 additions and 16 deletions

View File

@ -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`

View File

@ -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' }),

View File

@ -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;