]>
Commit | Line | Data |
---|---|---|
1 | import * as program from 'commander' | |
2 | import { getClient, Server, serverLogin } from '../../shared/extra-utils' | |
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 | if ( | |
11 | !program['url'] || | |
12 | !program['username'] || | |
13 | !program['password'] | |
14 | ) { | |
15 | if (!program['url']) console.error('--url field is required.') | |
16 | if (!program['username']) console.error('--username field is required.') | |
17 | if (!program['password']) console.error('--password field is required.') | |
18 | ||
19 | process.exit(-1) | |
20 | } | |
21 | ||
22 | getClient(program.url) | |
23 | .then(res => { | |
24 | const server = { | |
25 | url: program['url'], | |
26 | user: { | |
27 | username: program['username'], | |
28 | password: program['password'] | |
29 | }, | |
30 | client: { | |
31 | id: res.body.client_id, | |
32 | secret: res.body.client_secret | |
33 | } | |
34 | } as Server | |
35 | ||
36 | return serverLogin(server) | |
37 | }) | |
38 | .then(accessToken => { | |
39 | console.log(accessToken) | |
40 | process.exit(0) | |
41 | }) | |
42 | .catch(err => { | |
43 | console.error(err) | |
44 | process.exit(-1) | |
45 | }) |