This repository was archived by the owner on Nov 3, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcreate.js
58 lines (50 loc) · 1.4 KB
/
create.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const {flags} = require('@oclif/command');
const BaseCommand = require('../../base');
class SSHKeysCreateCommand extends BaseCommand {
async run() {
const {flags} = this.parse(SSHKeysCreateCommand);
const {api, styledJSON} = this;
let {name, key} = flags;
const {isTTY} = process.stdout;
if (!name && isTTY) {
const {askName} = require('../../prompts');
const {sshKeyName} = await askName(
'sshKey',
'Give a name to your ssh_key:'
);
name = sshKeyName;
}
if (!key && isTTY) {
const {askSSHKey} = require('../../prompts');
const {sshKey} = await askSSHKey();
key = sshKey;
}
const config = {
name,
public_key: key
};
try {
const {body} = await api.accountAddKey(config);
if (flags.json) {
this.log(styledJSON(body));
} else {
this.log(body.ssh_key.name, 'created!');
}
} catch (error) {
this.error(error.message);
}
}
}
SSHKeysCreateCommand.description = `add new SSH key in your account`;
SSHKeysCreateCommand.flags = {
name: flags.string({
char: 'n',
description: 'The name to give to the new SSH key in your account'
}),
key: flags.string({
char: 'k',
description: 'A string containing the entire public key'
}),
json: flags.boolean({char: 'j', description: 'Output in json format'})
};
module.exports = SSHKeysCreateCommand;