PeerTube/server/tools/peertube-get-access-token.ts

38 lines
914 B
TypeScript
Raw Normal View History

import { registerTSPaths } from '../helpers/register-ts-paths'
registerTSPaths()
2021-06-25 17:48:27 +02:00
import { program } from 'commander'
2021-07-13 11:44:16 +02:00
import { assignToken, buildServer } from './cli'
2017-09-07 17:58:09 +02:00
program
.option('-u, --url <url>', 'Server url')
.option('-n, --username <username>', 'Username')
.option('-p, --password <token>', 'Password')
.parse(process.argv)
2021-02-03 09:33:05 +01:00
const options = program.opts()
2017-09-07 17:58:09 +02:00
if (
2021-02-03 09:33:05 +01:00
!options.url ||
!options.username ||
!options.password
2017-09-07 17:58:09 +02:00
) {
2021-02-03 09:33:05 +01:00
if (!options.url) console.error('--url field is required.')
if (!options.username) console.error('--username field is required.')
if (!options.password) console.error('--password field is required.')
2019-06-13 11:09:38 +02:00
process.exit(-1)
2017-09-07 17:58:09 +02:00
}
2021-07-13 11:44:16 +02:00
const server = buildServer(options.url)
assignToken(server, options.username, options.password)
.then(() => {
console.log(server.accessToken)
2017-09-07 17:58:09 +02:00
process.exit(0)
})
.catch(err => {
console.error(err)
process.exit(-1)
})