]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tools/peertube-get-access-token.ts
d59a3632e4e4bec56fccebbaf05d501db500b308
[github/Chocobozzz/PeerTube.git] / server / tools / peertube-get-access-token.ts
1 import { program } from 'commander'
2 import { assignToken, buildServer } from './cli'
3
4 program
5 .option('-u, --url <url>', 'Server url')
6 .option('-n, --username <username>', 'Username')
7 .option('-p, --password <token>', 'Password')
8 .parse(process.argv)
9
10 const options = program.opts()
11
12 if (
13 !options.url ||
14 !options.username ||
15 !options.password
16 ) {
17 if (!options.url) console.error('--url field is required.')
18 if (!options.username) console.error('--username field is required.')
19 if (!options.password) console.error('--password field is required.')
20
21 process.exit(-1)
22 }
23
24 const server = buildServer(options.url)
25
26 assignToken(server, options.username, options.password)
27 .then(() => {
28 console.log(server.accessToken)
29 process.exit(0)
30 })
31 .catch(err => {
32 console.error(err)
33 process.exit(-1)
34 })