diff --git a/server/tools/cli.ts b/server/tools/cli.ts index cc89fe46e..7b94306cd 100644 --- a/server/tools/cli.ts +++ b/server/tools/cli.ts @@ -3,12 +3,12 @@ import { getAppNumber, isTestInstance } from '../helpers/core-utils' import { join } from 'path' import { root } from '../../shared/extra-utils/miscs/miscs' import { getVideoChannel } from '../../shared/extra-utils/videos/video-channels' -import { CommanderStatic } from 'commander' import { VideoChannel, VideoPrivacy } from '../../shared/models/videos' import { createLogger, format, transports } from 'winston' import { getMyUserInformation } from '@shared/extra-utils/users/users' import { User, UserRole } from '@shared/models' import { getAccessToken } from '@shared/extra-utils/users/login' +import { Command } from 'commander' let configName = 'PeerTube/CLI' if (isTestInstance()) configName += `-${getAppNumber()}` @@ -69,7 +69,7 @@ function deleteSettings () { } function getRemoteObjectOrDie ( - program: CommanderStatic, + program: Command, settings: Settings, netrc: Netrc ): { url: string, username: string, password: string } { @@ -106,7 +106,7 @@ function getRemoteObjectOrDie ( } } -function buildCommonVideoOptions (command: CommanderStatic) { +function buildCommonVideoOptions (command: Command) { function list (val) { return val.split(',') } @@ -128,7 +128,7 @@ function buildCommonVideoOptions (command: CommanderStatic) { .option('-v, --verbose ', 'Verbosity, from 0/\'error\' to 4/\'debug\'', 'info') } -async function buildVideoAttributesFromCommander (url: string, command: CommanderStatic, defaultAttributes: any = {}) { +async function buildVideoAttributesFromCommander (url: string, command: Command, defaultAttributes: any = {}) { const options = command.opts() const defaultBooleanAttributes = { @@ -177,7 +177,7 @@ async function buildVideoAttributesFromCommander (url: string, command: Commande return videoAttributes } -function getServerCredentials (program: CommanderStatic) { +function getServerCredentials (program: Command) { return Promise.all([ getSettings(), getNetrc() ]) .then(([ settings, netrc ]) => { return getRemoteObjectOrDie(program, settings, netrc) diff --git a/server/tools/peertube-auth.ts b/server/tools/peertube-auth.ts index e54649002..1934e7986 100644 --- a/server/tools/peertube-auth.ts +++ b/server/tools/peertube-auth.ts @@ -3,7 +3,7 @@ import { registerTSPaths } from '../helpers/register-ts-paths' registerTSPaths() -import * as program from 'commander' +import { OptionValues, program } from 'commander' import * as prompt from 'prompt' import { getNetrc, getSettings, writeSettings } from './cli' import { isUserUsernameValid } from '../helpers/custom-validators/users' @@ -66,7 +66,7 @@ program .option('-U, --username ', 'Username') .option('-p, --password ', 'Password') .option('--default', 'add the entry as the new default') - .action((options: program.OptionValues) => { + .action((options: OptionValues) => { /* eslint-disable no-import-assign */ prompt.override = options prompt.start() diff --git a/server/tools/peertube-get-access-token.ts b/server/tools/peertube-get-access-token.ts index b2c278c48..9488eba0e 100644 --- a/server/tools/peertube-get-access-token.ts +++ b/server/tools/peertube-get-access-token.ts @@ -1,7 +1,7 @@ import { registerTSPaths } from '../helpers/register-ts-paths' registerTSPaths() -import * as program from 'commander' +import { program } from 'commander' import { getClient, Server, serverLogin } from '../../shared/extra-utils' program diff --git a/server/tools/peertube-import-videos.ts b/server/tools/peertube-import-videos.ts index b3f57a8f9..101a95b2a 100644 --- a/server/tools/peertube-import-videos.ts +++ b/server/tools/peertube-import-videos.ts @@ -1,7 +1,7 @@ import { registerTSPaths } from '../helpers/register-ts-paths' registerTSPaths() -import * as program from 'commander' +import { program } from 'commander' import { accessSync, constants } from 'fs' import { remove } from 'fs-extra' import { truncate } from 'lodash' diff --git a/server/tools/peertube-plugins.ts b/server/tools/peertube-plugins.ts index cb591377b..54ea1264d 100644 --- a/server/tools/peertube-plugins.ts +++ b/server/tools/peertube-plugins.ts @@ -3,13 +3,12 @@ import { registerTSPaths } from '../helpers/register-ts-paths' registerTSPaths() -import * as program from 'commander' +import { program, Command, OptionValues } from 'commander' import { installPlugin, listPlugins, uninstallPlugin, updatePlugin } from '../../shared/extra-utils/server/plugins' import { getAdminTokenOrDie, getServerCredentials } from './cli' import { PeerTubePlugin, PluginType } from '../../shared/models' import { isAbsolute } from 'path' import * as CliTable3 from 'cli-table3' -import commander = require('commander') program .name('plugins') @@ -62,7 +61,7 @@ program.parse(process.argv) // ---------------------------------------------------------------------------- -async function pluginsListCLI (command: commander.CommanderStatic, options: commander.OptionValues) { +async function pluginsListCLI (command: Command, options: OptionValues) { const { url, username, password } = await getServerCredentials(command) const accessToken = await getAdminTokenOrDie(url, username, password) @@ -101,7 +100,7 @@ async function pluginsListCLI (command: commander.CommanderStatic, options: comm process.exit(0) } -async function installPluginCLI (command: commander.CommanderStatic, options: commander.OptionValues) { +async function installPluginCLI (command: Command, options: OptionValues) { if (!options.path && !options.npmName) { console.error('You need to specify the npm name or the path of the plugin you want to install.\n') program.outputHelp() @@ -132,7 +131,7 @@ async function installPluginCLI (command: commander.CommanderStatic, options: co process.exit(0) } -async function updatePluginCLI (command: commander.CommanderStatic, options: commander.OptionValues) { +async function updatePluginCLI (command: Command, options: OptionValues) { if (!options.path && !options.npmName) { console.error('You need to specify the npm name or the path of the plugin you want to update.\n') program.outputHelp() @@ -163,7 +162,7 @@ async function updatePluginCLI (command: commander.CommanderStatic, options: com process.exit(0) } -async function uninstallPluginCLI (command: commander.CommanderStatic, options: commander.OptionValues) { +async function uninstallPluginCLI (command: Command, options: OptionValues) { if (!options.npmName) { console.error('You need to specify the npm name of the plugin/theme you want to uninstall.\n') program.outputHelp() diff --git a/server/tools/peertube-redundancy.ts b/server/tools/peertube-redundancy.ts index 5bc80ddb9..4810deee0 100644 --- a/server/tools/peertube-redundancy.ts +++ b/server/tools/peertube-redundancy.ts @@ -3,7 +3,7 @@ import { registerTSPaths } from '../helpers/register-ts-paths' registerTSPaths() -import * as program from 'commander' +import { program, Command } from 'commander' import { getAdminTokenOrDie, getServerCredentials } from './cli' import { VideoRedundanciesTarget, VideoRedundancy } from '@shared/models' import { addVideoRedundancy, listVideoRedundancies, removeVideoRedundancy } from '@shared/extra-utils/server/redundancy' @@ -14,7 +14,6 @@ import { URL } from 'url' import { uniq } from 'lodash' import bytes = require('bytes') -import commander = require('commander') program .name('plugins') @@ -105,7 +104,7 @@ async function listRedundanciesCLI (target: VideoRedundanciesTarget) { process.exit(0) } -async function addRedundancyCLI (options: { video: number }, command: commander.CommanderStatic) { +async function addRedundancyCLI (options: { video: number }, command: Command) { const { url, username, password } = await getServerCredentials(command) const accessToken = await getAdminTokenOrDie(url, username, password) @@ -138,7 +137,7 @@ async function addRedundancyCLI (options: { video: number }, command: commander. } } -async function removeRedundancyCLI (options: { video: number }, command: commander.CommanderStatic) { +async function removeRedundancyCLI (options: { video: number }, command: Command) { const { url, username, password } = await getServerCredentials(command) const accessToken = await getAdminTokenOrDie(url, username, password) diff --git a/server/tools/peertube-upload.ts b/server/tools/peertube-upload.ts index 86c7f3d91..02edbd809 100644 --- a/server/tools/peertube-upload.ts +++ b/server/tools/peertube-upload.ts @@ -1,7 +1,7 @@ import { registerTSPaths } from '../helpers/register-ts-paths' registerTSPaths() -import * as program from 'commander' +import { program } from 'commander' import { access, constants } from 'fs-extra' import { isAbsolute } from 'path' import { getAccessToken } from '../../shared/extra-utils' diff --git a/server/tools/peertube-watch.ts b/server/tools/peertube-watch.ts index 3ca3e242a..892c9e7a6 100644 --- a/server/tools/peertube-watch.ts +++ b/server/tools/peertube-watch.ts @@ -1,7 +1,7 @@ import { registerTSPaths } from '../helpers/register-ts-paths' registerTSPaths() -import * as program from 'commander' +import { program, Option, OptionValues } from 'commander' import { join } from 'path' import { execSync } from 'child_process' @@ -9,7 +9,7 @@ program .name('watch') .arguments('') .addOption( - new program.Option('-g, --gui ', 'player type') + new Option('-g, --gui ', 'player type') .default('vlc') .choices([ 'airplay', 'stdout', 'chromecast', 'mpv', 'vlc', 'mplayer', 'xbmc' ]) ) @@ -22,7 +22,7 @@ program .action((url, options) => run(url, options)) .parse(process.argv) -function run (url: string, options: program.OptionValues) { +function run (url: string, options: OptionValues) { if (!url) { console.error(' positional argument is required.') process.exit(-1) diff --git a/server/tools/peertube.ts b/server/tools/peertube.ts index 655f07f0c..a40c1332e 100644 --- a/server/tools/peertube.ts +++ b/server/tools/peertube.ts @@ -5,7 +5,7 @@ import { registerTSPaths } from '../helpers/register-ts-paths' registerTSPaths() -import * as program from 'commander' +import { CommandOptions, program } from 'commander' import { getSettings, version } from './cli' program @@ -28,11 +28,11 @@ program .command( 'diagnostic [action]', 'like couple therapy, but for your instance', - { noHelp: true } as program.CommandOptions + { noHelp: true } as CommandOptions ).alias('d') .command('admin', 'manage an instance where you have elevated rights', - { noHelp: true } as program.CommandOptions + { noHelp: true } as CommandOptions ).alias('a') // help on no command diff --git a/server/tools/test.ts b/server/tools/test.ts index fc7f8d769..fbdbae0b0 100644 --- a/server/tools/test.ts +++ b/server/tools/test.ts @@ -2,7 +2,7 @@ import { registerTSPaths } from '../helpers/register-ts-paths' registerTSPaths() import { LiveVideo, LiveVideoCreate, VideoPrivacy } from '@shared/models' -import * as program from 'commander' +import { program } from 'commander' import { createLive, flushAndRunServer,