aboutsummaryrefslogtreecommitdiffhomepage
path: root/apps/peertube-cli/src/peertube-get-access-token.ts
diff options
context:
space:
mode:
Diffstat (limited to 'apps/peertube-cli/src/peertube-get-access-token.ts')
-rw-r--r--apps/peertube-cli/src/peertube-get-access-token.ts39
1 files changed, 39 insertions, 0 deletions
diff --git a/apps/peertube-cli/src/peertube-get-access-token.ts b/apps/peertube-cli/src/peertube-get-access-token.ts
new file mode 100644
index 000000000..3e0013182
--- /dev/null
+++ b/apps/peertube-cli/src/peertube-get-access-token.ts
@@ -0,0 +1,39 @@
1import { Command } from '@commander-js/extra-typings'
2import { assignToken, buildServer } from './shared/index.js'
3
4export function defineGetAccessProgram () {
5 const program = new Command()
6 .name('get-access-token')
7 .description('Get a peertube access token')
8 .alias('token')
9
10 program
11 .option('-u, --url <url>', 'Server url')
12 .option('-n, --username <username>', 'Username')
13 .option('-p, --password <token>', 'Password')
14 .action(async options => {
15 try {
16 if (
17 !options.url ||
18 !options.username ||
19 !options.password
20 ) {
21 if (!options.url) console.error('--url field is required.')
22 if (!options.username) console.error('--username field is required.')
23 if (!options.password) console.error('--password field is required.')
24
25 process.exit(-1)
26 }
27
28 const server = buildServer(options.url)
29 await assignToken(server, options.username, options.password)
30
31 console.log(server.accessToken)
32 } catch (err) {
33 console.error('Cannot get access token: ' + err.message)
34 process.exit(-1)
35 }
36 })
37
38 return program
39}