-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlist.ts
108 lines (93 loc) · 3.55 KB
/
list.ts
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import { Flags } from '@oclif/core'
import chalk from 'chalk'
import { ControlBaseCommand } from '../../control-base-command.js'
export default class IntegrationsListCommand extends ControlBaseCommand {
static description = 'List all integration rules'
static examples = [
'$ ably integrations list',
'$ ably integrations list --app "My App" --json',
'$ ably integrations list --app "My App" --pretty-json']
static flags = {
...ControlBaseCommand.globalFlags,
'app': Flags.string({
description: 'App ID or name to list integration rules for',
required: false,
}),
}
async run(): Promise<void> {
const { flags } = await this.parse(IntegrationsListCommand)
// Display authentication information
this.showAuthInfoIfNeeded(flags)
const controlApi = this.createControlApi(flags)
let appId: string | undefined;
try {
// Get app ID from flags or config
appId = await this.resolveAppId(flags)
if (!appId) {
if (this.shouldOutputJson(flags)) {
this.log(this.formatJsonOutput({
error: 'No app specified. Use --app flag or select an app with "ably apps switch"',
status: 'error',
success: false
}, flags));
} else {
this.error('No app specified. Use --app flag or select an app with "ably apps switch"');
}
return;
}
const rules = await controlApi.listRules(appId)
if (this.shouldOutputJson(flags)) {
this.log(this.formatJsonOutput({
appId,
rules: rules.map(rule => ({
appId: rule.appId,
created: new Date(rule.created).toISOString(),
id: rule.id,
modified: new Date(rule.modified).toISOString(),
requestMode: rule.requestMode,
source: {
channelFilter: rule.source.channelFilter || null,
type: rule.source.type
},
target: rule.target,
type: rule.ruleType,
version: rule.version
})),
success: true,
timestamp: new Date().toISOString(),
total: rules.length
}, flags));
} else {
if (rules.length === 0) {
this.log('No integration rules found');
return;
}
this.log(`Found ${rules.length} integration rules:\n`);
for (const rule of rules) {
this.log(chalk.bold(`Rule ID: ${rule.id}`));
this.log(` App ID: ${rule.appId}`);
this.log(` Type: ${rule.ruleType}`);
this.log(` Request Mode: ${rule.requestMode}`);
this.log(` Source Type: ${rule.source.type}`);
this.log(` Channel Filter: ${rule.source.channelFilter || '(none)'}`);
this.log(` Target: ${this.formatJsonOutput(rule.target as Record<string, unknown>, flags).replaceAll('\n', '\n ')}`);
this.log(` Version: ${rule.version}`);
this.log(` Created: ${this.formatDate(rule.created)}`);
this.log(` Updated: ${this.formatDate(rule.modified)}`);
this.log(''); // Add a blank line between rules
}
}
} catch (error) {
if (this.shouldOutputJson(flags)) {
this.log(this.formatJsonOutput({
appId,
error: error instanceof Error ? error.message : String(error),
status: 'error',
success: false
}, flags));
} else {
this.error(`Error listing integration rules: ${error instanceof Error ? error.message : String(error)}`);
}
}
}
}