1
0
Fork 0
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 15:48:27 +00:00
import { program } from 'commander'
2021-07-13 09:44:16 +00:00
import { assignToken, buildServer } from './cli'
2017-09-07 15:58:09 +00:00
program
.option('-u, --url <url>', 'Server url')
.option('-n, --username <username>', 'Username')
.option('-p, --password <token>', 'Password')
.parse(process.argv)
2021-02-03 08:33:05 +00:00
const options = program.opts()
2017-09-07 15:58:09 +00:00
if (
2021-02-03 08:33:05 +00:00
!options.url ||
!options.username ||
!options.password
2017-09-07 15:58:09 +00:00
) {
2021-02-03 08:33:05 +00: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 09:09:38 +00:00
process.exit(-1)
2017-09-07 15:58:09 +00:00
}
2021-07-13 09:44:16 +00:00
const server = buildServer(options.url)
assignToken(server, options.username, options.password)
.then(() => {
console.log(server.accessToken)
2017-09-07 15:58:09 +00:00
process.exit(0)
})
.catch(err => {
console.error(err)
process.exit(-1)
})