Skip to content

Commit 25dbf37

Browse files
frostebiteclaude
andcommitted
refactor(cli): move cache command under orchestrate subcommand
Cache is an orchestrator feature, so it belongs under `game-ci orchestrate cache` rather than as a top-level `game-ci cache` command. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 39f885d commit 25dbf37

File tree

5 files changed

+19
-27
lines changed

5 files changed

+19
-27
lines changed

src/cli.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
#!/usr/bin/env node
22

33
import yargs from 'yargs';
4-
// eslint-disable-next-line import/no-unresolved
54
import { hideBin } from 'yargs/helpers';
65
import buildCommand from './cli/commands/build';
76
import activateCommand from './cli/commands/activate';
87
import orchestrateCommand from './cli/commands/orchestrate';
9-
import cacheCommand from './cli/commands/cache';
108
import statusCommand from './cli/commands/status';
119
import versionCommand from './cli/commands/version';
1210
import updateCommand from './cli/commands/update';
@@ -18,7 +16,6 @@ const cli = yargs(hideBin(process.argv))
1816
.command(buildCommand)
1917
.command(activateCommand)
2018
.command(orchestrateCommand)
21-
.command(cacheCommand)
2219
.command(statusCommand)
2320
.command(versionCommand)
2421
.command(updateCommand)

src/cli/__tests__/cli-integration.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ describe('CLI integration', () => {
3838
expect(result.stdout).toContain('build');
3939
expect(result.stdout).toContain('activate');
4040
expect(result.stdout).toContain('orchestrate');
41-
expect(result.stdout).toContain('cache');
4241
expect(result.stdout).toContain('status');
4342
expect(result.stdout).toContain('version');
4443
expect(result.stdout).toContain('update');
@@ -83,6 +82,7 @@ describe('CLI integration', () => {
8382
expect(result.code).toStrictEqual(0);
8483
expect(result.stdout).toContain('--target-platform');
8584
expect(result.stdout).toContain('--provider-strategy');
85+
expect(result.stdout).toContain('cache');
8686
});
8787

8888
it('exits 0 for activate --help', async () => {
@@ -92,8 +92,8 @@ describe('CLI integration', () => {
9292
expect(result.stdout).toContain('activate');
9393
});
9494

95-
it('exits 0 for cache --help', async () => {
96-
const result = await runCli(['cache', '--help']);
95+
it('exits 0 for orchestrate cache --help', async () => {
96+
const result = await runCli(['orchestrate', 'cache', '--help']);
9797

9898
expect(result.code).toStrictEqual(0);
9999
expect(result.stdout).toContain('cache');

src/cli/__tests__/commands.test.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import buildCommand from '../commands/build';
22
import activateCommand from '../commands/activate';
33
import orchestrateCommand from '../commands/orchestrate';
4-
import cacheCommand from '../commands/cache';
54
import statusCommand from '../commands/status';
65
import versionCommand from '../commands/version';
76
import updateCommand from '../commands/update';
@@ -13,6 +12,7 @@ function createFakeYargs(): { yargs: any; options: Record<string, any> } {
1312
positional: jest.fn(),
1413
example: jest.fn(),
1514
env: jest.fn(),
15+
command: jest.fn(),
1616
};
1717

1818
yargs.option.mockImplementation((name: string, config: any) => {
@@ -27,6 +27,7 @@ function createFakeYargs(): { yargs: any; options: Record<string, any> } {
2727
});
2828
yargs.example.mockReturnValue(yargs);
2929
yargs.env.mockReturnValue(yargs);
30+
yargs.command.mockReturnValue(yargs);
3031

3132
return { yargs, options };
3233
}
@@ -165,7 +166,6 @@ describe('CLI commands', () => {
165166
(orchestrateCommand.builder as Function)(yargs);
166167

167168
expect(options['target-platform']).toBeDefined();
168-
expect(options['target-platform'].demandOption).toStrictEqual(true);
169169
expect(options['provider-strategy']).toBeDefined();
170170
expect(options['provider-strategy'].default).toStrictEqual('aws');
171171
expect(options['aws-stack-name']).toBeDefined();
@@ -175,23 +175,13 @@ describe('CLI commands', () => {
175175
expect(options['watch-to-end']).toBeDefined();
176176
expect(options['clone-depth']).toBeDefined();
177177
});
178-
});
179178

180-
describe('cache command', () => {
181-
it('exports the correct command name', () => {
182-
expect(cacheCommand.command).toStrictEqual('cache <action>');
183-
});
179+
it('registers cache as a subcommand', () => {
180+
const { yargs } = createFakeYargs();
184181

185-
it('has a description', () => {
186-
expect(cacheCommand.describe).toBeTruthy();
187-
});
188-
189-
it('has a builder function', () => {
190-
expect(typeof cacheCommand.builder).toStrictEqual('function');
191-
});
182+
(orchestrateCommand.builder as Function)(yargs);
192183

193-
it('has a handler function', () => {
194-
expect(typeof cacheCommand.handler).toStrictEqual('function');
184+
expect(yargs.command).toHaveBeenCalled();
195185
});
196186
});
197187

src/cli/commands/cache.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ const cacheCommand: CommandModule = {
2424
description: 'Path to the Unity project',
2525
default: '.',
2626
})
27-
.example('game-ci cache list', 'List all cached workspaces')
28-
.example('game-ci cache restore --cache-dir ./my-cache', 'Restore a cached workspace')
29-
.example('game-ci cache clear', 'Clear all cached workspaces');
27+
.example('game-ci orchestrate cache list', 'List all cached workspaces')
28+
.example('game-ci orchestrate cache restore --cache-dir ./my-cache', 'Restore a cached workspace')
29+
.example('game-ci orchestrate cache clear', 'Clear all cached workspaces');
3030
},
3131
handler: async (cliArguments) => {
3232
const action = cliArguments.action as string;

src/cli/commands/orchestrate.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { CommandModule } from 'yargs';
22
import * as core from '@actions/core';
33
import { BuildParameters, ImageTag, Orchestrator } from '../../model';
44
import { mapCliArgumentsToInput, CliArguments } from '../input-mapper';
5+
import cacheCommand from './cache';
56

67
interface OrchestrateArguments extends CliArguments {
78
targetPlatform: string;
@@ -10,14 +11,14 @@ interface OrchestrateArguments extends CliArguments {
1011

1112
const orchestrateCommand: CommandModule<object, OrchestrateArguments> = {
1213
command: 'orchestrate',
13-
describe: 'Run a build via orchestrator providers (AWS, Kubernetes, etc.)',
14+
describe: 'Orchestrator — remote builds, cache management, and provider tools',
1415
builder: (yargs) => {
1516
return yargs
17+
.command(cacheCommand)
1618
.option('target-platform', {
1719
alias: 'targetPlatform',
1820
type: 'string',
1921
description: 'Platform that the build should target',
20-
demandOption: true,
2122
})
2223
.option('provider-strategy', {
2324
alias: 'providerStrategy',
@@ -188,6 +189,10 @@ const orchestrateCommand: CommandModule<object, OrchestrateArguments> = {
188189
},
189190
handler: async (cliArguments) => {
190191
try {
192+
if (!cliArguments.targetPlatform) {
193+
throw new Error('--target-platform is required for orchestrate builds. Run game-ci orchestrate --help.');
194+
}
195+
191196
mapCliArgumentsToInput(cliArguments);
192197

193198
const buildParameters = await BuildParameters.create();

0 commit comments

Comments
 (0)