Skip to content

Commit 0a1d085

Browse files
author
Vlad Velici
committed
move stats to top-level command
1 parent 89d145e commit 0a1d085

9 files changed

Lines changed: 62 additions & 122 deletions

File tree

docs/Product-Requirements.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ The CLI uses topics (space-separated) to group related commands logically.
3434
- `$ ably accounts list`: Lists locally configured accounts (aliases, token details, user info, account details).
3535
- `$ ably accounts logout [ALIAS]`: Removes the access token and associated data for the specified (or default) account after warning.
3636
- `$ ably accounts current`: Shows the currently selected account (alias or `default`) and verifies the token against the Control API `/me` endpoint.
37-
- `$ ably accounts stats`: Views account stats. Supports `--live` for polling key metrics (peak connections, channels, message throughput, etc.).
3837
- `$ ably accounts switch [ALIAS]`: Switches the active account configuration to the specified alias or prompts for selection.
3938

4039
**App Management (`ably apps`)**
@@ -45,7 +44,6 @@ The CLI uses topics (space-separated) to group related commands logically.
4544
- `$ ably apps update ID`: Updates the app specified by `ID`. Supports `--name`, `--tls-only`.
4645
- `$ ably apps delete [ID]`: Deletes the specified (or current) app after confirmation. Supports `--force`.
4746
- `$ ably apps set-apns-p12 ID`: Uploads an APNS P12 certificate for the specified app `ID`. Requires `--certificate`. Supports `--password`, `--use-for-sandbox`.
48-
- `$ ably apps stats [ID]`: Views app stats for the specified (or current) app. Supports `--live` polling, `--unit`, `--start`, `--end`, `--limit`.
4947
- `$ ably apps switch [APPID]`: Switches the active app configuration to the specified App ID or prompts for selection.
5048
- `$ ably apps current`: Shows the currently selected app configuration.
5149
- `$ ably apps logs subscribe`: Alias for `ably logs app subscribe`.
@@ -158,6 +156,12 @@ The CLI uses topics (space-separated) to group related commands logically.
158156
- `$ ably queues create`: Creates a queue. Requires various flags.
159157
- `$ ably queues delete QUEUENAME`: Deletes a queue after confirmation. Supports `--force`.
160158

159+
**Statistics (`ably stats`)**
160+
*(View usage statistics for accounts and apps)*
161+
162+
- `$ ably stats account`: Views account stats. Supports `--live` for polling key metrics (peak connections, channels, message throughput, etc.), `--unit`, `--start`, `--end`, `--limit`.
163+
- `$ ably stats app [ID]`: Views app stats for the specified (or current) app. Supports `--live` polling, `--unit`, `--start`, `--end`, `--limit`.
164+
161165
**Benchmarking (`ably bench`)**
162166
*(Run benchmark tests)*
163167

@@ -316,7 +320,7 @@ The `AblyCliTerminal` React component can optionally support a split-screen mode
316320
- Uses a distinct client ID prefix (`ably-mcp-`).
317321
- **Available MCP Commands (Subset of CLI)**:
318322
- `ably apps list`
319-
- `ably apps stats`
323+
- `ably stats app`
320324
- `ably auth keys list`
321325
- `ably channels history`
322326
- `ably channels publish`

docs/TODO.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@
7272
- [ ] Test app update with partial data
7373
- [ ] Test P12 certificate file upload handling
7474
- [ ] Test failure scenarios: duplicate app names, API error mapping
75-
- [ ] `apps stats`: Mock Control API calls, flag handling, output formats.
75+
- [ ] **Stats:**
76+
- [ ] `stats account`: Mock Control API calls, flag handling, output formats.
77+
- [ ] Test stats parsing and formatting for different time ranges
78+
- [ ] Test --live polling functionality with mocked responses
79+
- [ ] `stats app`: Mock Control API calls, flag handling, output formats.
7680
- [ ] Test stats parsing and formatting for different time ranges
7781
- [ ] Test --live polling functionality with mocked responses
7882
- [ ] `apps logs history/subscribe`: Mock Control API/SDK, flag handling, output formats, SIGINT handling.

src/commands/accounts/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,5 @@ export default class AccountsCommand extends BaseTopicCommand {
1212
"$ ably accounts current",
1313
"$ ably accounts logout",
1414
"$ ably accounts switch my-account",
15-
"$ ably accounts stats",
1615
];
1716
}

src/commands/accounts/stats/README.md

Lines changed: 0 additions & 77 deletions
This file was deleted.

src/commands/apps/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export default class AppsCommand extends BaseTopicCommand {
1212
"$ ably apps update",
1313
"$ ably apps delete",
1414
"$ ably apps set-apns-p12",
15-
"$ ably apps stats",
1615
"$ ably apps channel-rules list",
1716
"$ ably apps switch my-app",
1817
];
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import { Flags } from "@oclif/core";
22
import chalk from "chalk";
33

4-
import { ControlBaseCommand } from "../../../control-base-command.js";
5-
import { StatsDisplay } from "../../../services/stats-display.js";
6-
import type { BaseFlags } from "../../../types/cli.js";
7-
import type { ControlApi } from "../../../services/control-api.js";
4+
import { ControlBaseCommand } from "../../control-base-command.js";
5+
import { StatsDisplay } from "../../services/stats-display.js";
6+
import type { BaseFlags } from "../../types/cli.js";
7+
import type { ControlApi } from "../../services/control-api.js";
88

9-
export default class AccountsStatsCommand extends ControlBaseCommand {
9+
export default class StatsAccountCommand extends ControlBaseCommand {
1010
static description = "Get account stats with optional live updates";
1111

1212
static examples = [
13-
"$ ably accounts stats",
14-
"$ ably accounts stats --unit hour",
15-
"$ ably accounts stats --start 1618005600000 --end 1618091999999",
16-
"$ ably accounts stats --limit 10",
17-
"$ ably accounts stats --json",
18-
"$ ably accounts stats --pretty-json",
19-
"$ ably accounts stats --live",
20-
"$ ably accounts stats --live --interval 15",
13+
"$ ably stats account",
14+
"$ ably stats account --unit hour",
15+
"$ ably stats account --start 1618005600000 --end 1618091999999",
16+
"$ ably stats account --limit 10",
17+
"$ ably stats account --json",
18+
"$ ably stats account --pretty-json",
19+
"$ ably stats account --live",
20+
"$ ably stats account --live --interval 15",
2121
];
2222

2323
static flags = {
@@ -57,7 +57,7 @@ export default class AccountsStatsCommand extends ControlBaseCommand {
5757
private statsDisplay: StatsDisplay | null = null; // Track when we're already fetching stats
5858

5959
async run(): Promise<void> {
60-
const { flags } = await this.parse(AccountsStatsCommand);
60+
const { flags } = await this.parse(StatsAccountCommand);
6161

6262
// For live stats, enforce minute interval
6363
if (flags.live && flags.unit !== "minute") {
Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { Args, Flags } from "@oclif/core";
22
import chalk from "chalk";
3-
import { StatsDisplay } from "../../../services/stats-display.js";
4-
import { ControlBaseCommand } from "../../../control-base-command.js";
5-
import type { BaseFlags } from "../../../types/cli.js";
6-
import type { ControlApi } from "../../../services/control-api.js";
73

8-
export default class AppsStatsCommand extends ControlBaseCommand {
4+
import { ControlBaseCommand } from "../../control-base-command.js";
5+
import { StatsDisplay } from "../../services/stats-display.js";
6+
import type { BaseFlags } from "../../types/cli.js";
7+
import type { ControlApi } from "../../services/control-api.js";
8+
9+
export default class StatsAppCommand extends ControlBaseCommand {
910
static args = {
1011
id: Args.string({
1112
description: "App ID to get stats for (uses default app if not provided)",
@@ -16,17 +17,17 @@ export default class AppsStatsCommand extends ControlBaseCommand {
1617
static description = "Get app stats with optional live updates";
1718

1819
static examples = [
19-
"$ ably apps stats",
20-
"$ ably apps stats app-id",
21-
"$ ably apps stats --unit hour",
22-
"$ ably apps stats app-id --unit hour",
23-
"$ ably apps stats app-id --start 1618005600000 --end 1618091999999",
24-
"$ ably apps stats app-id --limit 10",
25-
"$ ably apps stats app-id --json",
26-
"$ ably apps stats app-id --pretty-json",
27-
"$ ably apps stats --live",
28-
"$ ably apps stats app-id --live",
29-
"$ ably apps stats --live --interval 15",
20+
"$ ably stats app",
21+
"$ ably stats app app-id",
22+
"$ ably stats app --unit hour",
23+
"$ ably stats app app-id --unit hour",
24+
"$ ably stats app app-id --start 1618005600000 --end 1618091999999",
25+
"$ ably stats app app-id --limit 10",
26+
"$ ably stats app app-id --json",
27+
"$ ably stats app app-id --pretty-json",
28+
"$ ably stats app --live",
29+
"$ ably stats app app-id --live",
30+
"$ ably stats app --live --interval 15",
3031
];
3132

3233
static flags = {
@@ -66,7 +67,7 @@ export default class AppsStatsCommand extends ControlBaseCommand {
6667
private statsDisplay: StatsDisplay | null = null; // Track when we're already fetching stats
6768

6869
async run(): Promise<void> {
69-
const { args, flags } = await this.parse(AppsStatsCommand);
70+
const { args, flags } = await this.parse(StatsAppCommand);
7071

7172
// Use provided app ID or fall back to default app ID
7273
const appId = args.id || this.configManager.getCurrentAppId();

src/commands/stats/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { BaseTopicCommand } from "../../base-topic-command.js";
2+
3+
export default class StatsCommand extends BaseTopicCommand {
4+
protected topicName = "stats";
5+
protected commandGroup = "stats";
6+
7+
static description = "View statistics for your Ably account or apps";
8+
9+
static examples = [
10+
"$ ably stats account",
11+
"$ ably stats account --unit hour",
12+
"$ ably stats account --live",
13+
"$ ably stats app",
14+
"$ ably stats app my-app-id",
15+
"$ ably stats app --live",
16+
];
17+
}

test/unit/commands/help-consistency.test.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,7 @@ describe("Help Output Consistency", () => {
141141
});
142142

143143
// Both should list the same commands (ignoring the ably prefix)
144-
const commands = [
145-
"current",
146-
"list",
147-
"login",
148-
"logout",
149-
"stats",
150-
"switch",
151-
];
144+
const commands = ["current", "list", "login", "logout", "switch"];
152145

153146
commands.forEach((cmd) => {
154147
expect(nonInteractive).toContain(`accounts ${cmd}`);

0 commit comments

Comments
 (0)