]>
Commit | Line | Data |
---|---|---|
12152aa0 | 1 | import { program } from 'commander' |
d0a0fa42 | 2 | import { assignToken, buildServer } from './cli' |
8df87ce7 C |
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 | ||
ba5a8d89 C |
10 | const options = program.opts() |
11 | ||
8df87ce7 | 12 | if ( |
ba5a8d89 C |
13 | !options.url || |
14 | !options.username || | |
15 | !options.password | |
8df87ce7 | 16 | ) { |
ba5a8d89 C |
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.') | |
1a12f66d | 20 | |
8704acf4 | 21 | process.exit(-1) |
8df87ce7 C |
22 | } |
23 | ||
d0a0fa42 C |
24 | const server = buildServer(options.url) |
25 | ||
26 | assignToken(server, options.username, options.password) | |
27 | .then(() => { | |
28 | console.log(server.accessToken) | |
8df87ce7 C |
29 | process.exit(0) |
30 | }) | |
31 | .catch(err => { | |
32 | console.error(err) | |
33 | process.exit(-1) | |
34 | }) |