Skip to content

Commit 6586fb0

Browse files
committed
refactor: remove legacy cli output paths
1 parent fcbf267 commit 6586fb0

19 files changed

Lines changed: 520 additions & 749 deletions

src/cli/commands/client-command.ts

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

src/cli/commands/generic.ts

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { AgentDeviceClient, CommandRequestResult } from '../../client.ts';
2-
import { announceReplayTestRun } from '../../cli-test.ts';
2+
import { announceReplayTestRun, renderReplayTestResponse } from '../../cli-test.ts';
33
import {
44
runSemanticCliCommand,
55
runSemanticCliCommandWithOutput,
@@ -10,8 +10,9 @@ import {
1010
type SemanticCliCommand,
1111
} from '../../commands/semantic-command-surface.ts';
1212
import type { SemanticCliOutput } from '../../commands/semantic-contract.ts';
13+
import type { ReplaySuiteResult } from '../../daemon/types.ts';
1314
import type { CliFlags } from '../../utils/command-schema.ts';
14-
import { writeCommandCliOutput } from './output.ts';
15+
import { readCommandMessage } from '../../utils/success-text.ts';
1516
import { writeCommandOutput } from './shared.ts';
1617
import type { PublicCommandName } from '../../command-catalog.ts';
1718
import type { ClientCommandHandler } from './router-types.ts';
@@ -31,18 +32,6 @@ const formattedSemanticCommandHandlers = Object.fromEntries(
3132

3233
export const dedicatedSemanticCommandHandlers = formattedSemanticCommandHandlers;
3334

34-
const clientMethodCommandNames = commandNameSet([
35-
'wait',
36-
'alert',
37-
'appstate',
38-
'back',
39-
'home',
40-
'rotate',
41-
'app-switcher',
42-
'keyboard',
43-
'clipboard',
44-
] as const satisfies readonly SemanticCliCommand[]);
45-
4635
const semanticGenericCommands = listSemanticCommandNames().filter(isGenericSemanticCliCommand);
4736

4837
const genericClientCommandRunners = Object.fromEntries(
@@ -73,14 +62,33 @@ function createGenericClientCommandHandler(
7362
): ClientCommandHandler {
7463
return async ({ positionals, flags, client }) => {
7564
const data = await run({ client, positionals, flags });
76-
const exitCode = writeCommandCliOutput(command, positionals, flags, data);
65+
const exitCode = writeGenericSemanticCliOutput(command, flags, data);
7766
if (exitCode !== 0) {
7867
process.exit(exitCode);
7968
}
8069
return true;
8170
};
8271
}
8372

73+
function writeGenericSemanticCliOutput(
74+
command: PublicCommandName,
75+
flags: CliFlags,
76+
data: CommandRequestResult,
77+
): number {
78+
if (command === 'test') {
79+
return renderReplayTestResponse({
80+
suite: data as ReplaySuiteResult,
81+
verbose: flags.verbose,
82+
json: flags.json,
83+
reportJunit: flags.reportJunit,
84+
});
85+
}
86+
writeCommandOutput(flags, data, () =>
87+
readCommandMessage(data as Record<string, unknown> | undefined),
88+
);
89+
return 0;
90+
}
91+
8492
function createFormattedSemanticHandler(command: SemanticCliCommand): ClientCommandHandler {
8593
return async ({ positionals, flags, client }) => {
8694
const { cliOutput } = await runSemanticCliCommandWithOutput({
@@ -110,13 +118,6 @@ function writeSemanticCliOutput(flags: CliFlags, output: SemanticCliOutput): voi
110118

111119
function isGenericSemanticCliCommand(command: SemanticCliCommand): boolean {
112120
return (
113-
!(command in formattedSemanticCommandHandlers) &&
114-
!clientMethodCommandNames.has(command) &&
115-
command !== 'screenshot' &&
116-
command !== 'diff'
121+
!(command in formattedSemanticCommandHandlers) && command !== 'screenshot' && command !== 'diff'
117122
);
118123
}
119-
120-
function commandNameSet<const TName extends string>(names: readonly TName[]): ReadonlySet<string> {
121-
return new Set(names);
122-
}

0 commit comments

Comments
 (0)