X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftools%2Fpeertube-auth.ts;h=1934e7986ea62bff00e8432c808340b161c37748;hb=12152aa09ff47dc5c5a627c27030855e254e58ad;hp=7673b92cd2db6adfb3b0fe8ec765ed3f3eb72325;hpb=8e76aa1d75aebdadd0451d2e57c9bb65d1e75b9a;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tools/peertube-auth.ts b/server/tools/peertube-auth.ts index 7673b92cd..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' @@ -46,6 +46,15 @@ function isURLaPeerTubeInstance (url: string) { return url.startsWith('http://') || url.startsWith('https://') } +function stripExtraneousFromPeerTubeUrl (url: string) { + // Get everything before the 3rd /. + const urlLength = url.includes('/', 8) + ? url.indexOf('/', 8) + : url.length + + return url.substr(0, urlLength) +} + program .name('auth') .usage('[command] [options]') @@ -57,7 +66,8 @@ program .option('-U, --username ', 'Username') .option('-p, --password ', 'Password') .option('--default', 'add the entry as the new default') - .action(options => { + .action((options: OptionValues) => { + /* eslint-disable no-import-assign */ prompt.override = options prompt.start() prompt.get({ @@ -80,12 +90,6 @@ program } } }, async (_, result) => { - const stripExtraneousFromPeerTubeUrl = function (url: string) { - // Get everything before the 3rd /. - const urlLength: number = url.includes('/', 8) ? url.indexOf('/', 8) : url.length - - return url.substr(0, urlLength) - } // Check credentials try { @@ -99,7 +103,7 @@ program process.exit(-1) } - await setInstance(result.url, result.username, result.password, program['default']) + await setInstance(result.url, result.username, result.password, options.default) process.exit(0) }) @@ -157,15 +161,12 @@ program } }) -program.on('--help', function () { - console.log(' Examples:') - console.log() - console.log(' $ peertube auth add -u https://peertube.cpy.re -U "PEERTUBE_USER" --password "PEERTUBE_PASSWORD"') - console.log(' $ peertube auth add -u https://peertube.cpy.re -U root') - console.log(' $ peertube auth list') - console.log(' $ peertube auth del https://peertube.cpy.re') - console.log() -}) +program.addHelpText('after', '\n\n Examples:\n\n' + + ' $ peertube auth add -u https://peertube.cpy.re -U "PEERTUBE_USER" --password "PEERTUBE_PASSWORD"\n' + + ' $ peertube auth add -u https://peertube.cpy.re -U root\n' + + ' $ peertube auth list\n' + + ' $ peertube auth del https://peertube.cpy.re\n' +) if (!process.argv.slice(2).length) { program.outputHelp()