import { uniq } from 'lodash'
import bytes = require('bytes')
+import commander = require('commander')
program
.name('plugins')
.option('-U, --username <username>', 'Username')
.option('-p, --password <token>', 'Password')
.option('-v, --video <videoId>', 'Video id to duplicate')
- .action((options) => addRedundancyCLI(options))
+ .action((options, command) => addRedundancyCLI(options, command))
program
.command('remove')
.option('-U, --username <username>', 'Username')
.option('-p, --password <token>', 'Password')
.option('-v, --video <videoId>', 'Video id to remove from redundancies')
- .action((options) => removeRedundancyCLI(options))
+ .action((options, command) => removeRedundancyCLI(options, command))
if (!process.argv.slice(2).length) {
program.outputHelp()
process.exit(0)
}
-async function addRedundancyCLI (options: { videoId: number }) {
- const { url, username, password } = await getServerCredentials(program)
+async function addRedundancyCLI (options: { video: number }, command: commander.CommanderStatic) {
+ const { url, username, password } = await getServerCredentials(command)
const accessToken = await getAdminTokenOrDie(url, username, password)
- if (!options['video'] || validator.isInt('' + options['video']) === false) {
+ if (!options.video || validator.isInt('' + options.video) === false) {
console.error('You need to specify the video id to duplicate and it should be a number.\n')
- program.outputHelp()
+ command.outputHelp()
process.exit(-1)
}
await addVideoRedundancy({
url,
accessToken,
- videoId: options['video']
+ videoId: options.video
})
console.log('Video will be duplicated by your instance!')
}
}
-async function removeRedundancyCLI (options: { videoId: number }) {
- const { url, username, password } = await getServerCredentials(program)
+async function removeRedundancyCLI (options: { video: number }, command: commander.CommanderStatic) {
+ const { url, username, password } = await getServerCredentials(command)
const accessToken = await getAdminTokenOrDie(url, username, password)
- if (!options['video'] || validator.isInt('' + options['video']) === false) {
+ if (!options.video || validator.isInt('' + options.video) === false) {
console.error('You need to specify the video id to remove from your redundancies.\n')
- program.outputHelp()
+ command.outputHelp()
process.exit(-1)
}
- const videoId = parseInt(options['video'] + '', 10)
+ const videoId = parseInt(options.video + '', 10)
let redundancies = await listVideoRedundanciesData(url, accessToken, 'my-videos')
let videoRedundancy = redundancies.find(r => videoId === r.id)