fix(xen-api/examples/import-vdi): params handling

This commit is contained in:
Julien Fontanet 2023-11-20 11:45:45 +01:00
parent 1911386aba
commit 781b070e74

View File

@ -25,8 +25,15 @@ defer(async ($defer, argv) => {
const { raw, sr, vdi } = opts
const createVdi = vdi === ''
if (createVdi && !(raw && sr !== undefined)) {
throw new Error('--vdi requires --raw and --sr flags')
if (createVdi) {
if (sr === '') {
throw 'requires either --vdi or --sr'
}
if (!raw) {
throw 'creating a VDI requires --raw'
}
} else if (sr !== '') {
throw '--vdi and --sr are mutually exclusive'
}
const xapi = createClient({
@ -57,7 +64,7 @@ defer(async ($defer, argv) => {
})
$defer.onFailure(() => xapi.call('VDI.destroy', vdiRef))
} else {
vdiRef = await resolveRef(xapi, 'VDI', args[1])
vdiRef = await resolveRef(xapi, 'VDI', vdi)
}
if (opts['remove-length']) {
@ -78,4 +85,4 @@ defer(async ($defer, argv) => {
if (result !== undefined) {
console.log(result)
}
})(process.argv.slice(2)).catch(console.error.bind(console, 'error'))
})(process.argv.slice(2)).catch(console.error.bind(console, 'Fatal:'))