1
0
Fork 0

Fix CLI default boolean values

This commit is contained in:
Chocobozzz 2019-06-13 13:59:34 +02:00
parent b30acc0e4b
commit 6b226c3278
No known key found for this signature in database
GPG key ID: 583A612D890159BE
2 changed files with 11 additions and 3 deletions

View file

@ -158,6 +158,7 @@ describe('Test CLI wrapper', function () {
expect(videoDetails.channel.name).to.equal('user_channel') expect(videoDetails.channel.name).to.equal('user_channel')
expect(videoDetails.support).to.equal('support') expect(videoDetails.support).to.equal('support')
expect(videoDetails.nsfw).to.be.true expect(videoDetails.nsfw).to.be.true
expect(videoDetails.commentsEnabled).to.be.true
} }
}) })

View file

@ -117,15 +117,22 @@ function buildCommonVideoOptions (command: Command) {
} }
async function buildVideoAttributesFromCommander (url: string, command: Command, defaultAttributes: any) { async function buildVideoAttributesFromCommander (url: string, command: Command, defaultAttributes: any) {
const booleanAttributes: { [id: string]: boolean } = {} const defaultBooleanAttributes = {
nsfw: false,
commentsEnabled: true,
downloadEnabled: true,
waitTranscoding: true
}
for (const key of [ 'nsfw', 'commentsEnabled', 'downloadEnabled', 'waitTranscoding' ]) { const booleanAttributes: { [id in keyof typeof defaultBooleanAttributes]: boolean } | {} = {}
for (const key of Object.keys(defaultBooleanAttributes)) {
if (command[ key ] !== undefined) { if (command[ key ] !== undefined) {
booleanAttributes[key] = command[ key ] booleanAttributes[key] = command[ key ]
} else if (defaultAttributes[key] !== undefined) { } else if (defaultAttributes[key] !== undefined) {
booleanAttributes[key] = defaultAttributes[key] booleanAttributes[key] = defaultAttributes[key]
} else { } else {
booleanAttributes[key] = false booleanAttributes[key] = defaultBooleanAttributes[key]
} }
} }