]>
Commit | Line | Data |
---|---|---|
1 | import { program } from 'commander' | |
2 | import { assignToken, buildServer } from './shared' | |
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 | }) |