forked from rockcarver/frodo-cli
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathagent-java-delete.ts
More file actions
65 lines (61 loc) · 1.91 KB
/
agent-java-delete.ts
File metadata and controls
65 lines (61 loc) · 1.91 KB
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
59
60
61
62
63
64
65
import { state } from '@rockcarver/frodo-lib';
import { Option } from 'commander';
import { deleteJavaAgent, deleteJavaAgents } from '../../ops/AgentOps';
import { getTokens } from '../../ops/AuthenticateOps';
import { verboseMessage } from '../../utils/Console.js';
import { FrodoCommand } from '../FrodoCommand';
export default function setup() {
const program = new FrodoCommand('frodo agent java delete');
program
.description('Delete java agents.')
.addOption(
new Option(
'-i, --agent-id <agent-id>',
'Agent id. If specified, -a is ignored.'
)
)
.addOption(
new Option('-a, --all', 'Delete all java agents. Ignored with -i.')
)
.action(
// implement command logic inside action handler
async (host, realm, user, password, options, command) => {
command.handleDefaultArgsAndOpts(
host,
realm,
user,
password,
options,
command
);
if (await getTokens()) {
// delete by id
if (options.agentId) {
verboseMessage(
`Deleting agent '${
options.agentId
}' in realm "${state.getRealm()}"...`
);
const outcome = await deleteJavaAgent(options.agentId);
if (!outcome) process.exitCode = 1;
}
// --all -a
else if (options.all) {
verboseMessage('Deleting all agents...');
const outcome = await deleteJavaAgents();
if (!outcome) process.exitCode = 1;
}
// unrecognized combination of options or no options
else {
verboseMessage(
'Unrecognized combination of options or no options...'
);
program.outputHelp();
process.exitCode = 1;
}
}
}
// end command logic inside action handler
);
return program;
}