]>
Commit | Line | Data |
---|---|---|
8df87ce7 | 1 | import * as program from 'commander' |
8df87ce7 C |
2 | |
3 | import { | |
4 | getClient, | |
c1e791ba RK |
5 | serverLogin, |
6 | Server, | |
7 | Client, | |
8 | User | |
94565d52 | 9 | } from '../../shared/extra-utils' |
8df87ce7 C |
10 | |
11 | program | |
12 | .option('-u, --url <url>', 'Server url') | |
13 | .option('-n, --username <username>', 'Username') | |
14 | .option('-p, --password <token>', 'Password') | |
15 | .parse(process.argv) | |
16 | ||
17 | if ( | |
18 | !program['url'] || | |
19 | !program['username'] || | |
20 | !program['password'] | |
21 | ) { | |
8704acf4 RK |
22 | if (!program['url']) console.error('--url field is required.') |
23 | if (!program['username']) console.error('--username field is required.') | |
24 | if (!program['password']) console.error('--password field is required.') | |
25 | process.exit(-1) | |
8df87ce7 C |
26 | } |
27 | ||
8df87ce7 C |
28 | getClient(program.url) |
29 | .then(res => { | |
c1e791ba RK |
30 | const server = { |
31 | url: program['url'], | |
32 | user: { | |
33 | username: program['username'], | |
34 | password: program['password'] | |
35 | } as User, | |
36 | client: { | |
37 | id: res.body.client_id as string, | |
38 | secret: res.body.client_secret as string | |
39 | } as Client | |
40 | } as Server | |
8df87ce7 | 41 | |
eec63bbc | 42 | return serverLogin(server) |
8df87ce7 C |
43 | }) |
44 | .then(accessToken => { | |
45 | console.log(accessToken) | |
46 | process.exit(0) | |
47 | }) | |
48 | .catch(err => { | |
49 | console.error(err) | |
50 | process.exit(-1) | |
51 | }) |