Skip to content

Commit 367bec1

Browse files
committed
fix(cli): Align profile parsing with yargs
Use yargs-parser for builder-time --profile resolution so help-time\nrequiredness stays aligned with handler-time parsing. This removes\nthe manual argv scan that could diverge from command execution.\n\nAlso remove the unused resolveActiveCliSessionDefaults wrapper and\npoint the tests at the shared resolver directly.\n\nCo-Authored-By: OpenAI <noreply@openai.com>
1 parent 9e17302 commit 367bec1

File tree

5 files changed

+36
-41
lines changed

5 files changed

+36
-41
lines changed

docs/TOOLS-CLI.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,4 @@ XcodeBuildMCP provides 76 canonical tools organized into 14 workflow groups.
206206

207207
---
208208

209-
*This documentation is automatically generated by `scripts/update-tools-docs.ts` from the tools manifest. Last updated: 2026-03-07T20:17:02.262Z UTC*
209+
*This documentation is automatically generated by `scripts/update-tools-docs.ts` from the tools manifest. Last updated: 2026-03-07T20:50:55.840Z UTC*

docs/TOOLS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,4 @@ This document lists MCP tool names as exposed to MCP clients. XcodeBuildMCP prov
222222

223223
---
224224

225-
*This documentation is automatically generated by `scripts/update-tools-docs.ts` from the tools manifest. Last updated: 2026-03-07T20:17:02.262Z UTC*
225+
*This documentation is automatically generated by `scripts/update-tools-docs.ts` from the tools manifest. Last updated: 2026-03-07T20:50:55.840Z UTC*

src/cli/__tests__/session-defaults.test.ts

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,36 @@ import * as z from 'zod';
33
import {
44
mergeCliSessionDefaults,
55
pickSchemaSessionDefaults,
6-
resolveActiveCliSessionDefaults,
6+
resolveCliSessionDefaults,
77
} from '../session-defaults.ts';
88

99
describe('CLI session defaults', () => {
1010
it('uses the active profile without overlaying global defaults', () => {
11-
const defaults = resolveActiveCliSessionDefaults({
12-
enabledWorkflows: [],
13-
customWorkflows: {},
14-
debug: false,
15-
sentryDisabled: false,
16-
experimentalWorkflowDiscovery: false,
17-
disableSessionDefaults: true,
18-
disableXcodeAutoSync: false,
19-
uiDebuggerGuardMode: 'error',
20-
incrementalBuildsEnabled: false,
21-
dapRequestTimeoutMs: 30_000,
22-
dapLogEvents: false,
23-
launchJsonWaitMs: 8_000,
24-
debuggerBackend: 'dap',
25-
sessionDefaults: {
26-
workspacePath: 'Global.xcworkspace',
27-
},
28-
sessionDefaultsProfiles: {
29-
ios: {
30-
scheme: 'ProfileScheme',
11+
const defaults = resolveCliSessionDefaults({
12+
runtimeConfig: {
13+
enabledWorkflows: [],
14+
customWorkflows: {},
15+
debug: false,
16+
sentryDisabled: false,
17+
experimentalWorkflowDiscovery: false,
18+
disableSessionDefaults: true,
19+
disableXcodeAutoSync: false,
20+
uiDebuggerGuardMode: 'error',
21+
incrementalBuildsEnabled: false,
22+
dapRequestTimeoutMs: 30_000,
23+
dapLogEvents: false,
24+
launchJsonWaitMs: 8_000,
25+
debuggerBackend: 'dap',
26+
sessionDefaults: {
27+
workspacePath: 'Global.xcworkspace',
28+
},
29+
sessionDefaultsProfiles: {
30+
ios: {
31+
scheme: 'ProfileScheme',
32+
},
3133
},
34+
activeSessionDefaultsProfile: 'ios',
3235
},
33-
activeSessionDefaultsProfile: 'ios',
3436
});
3537

3638
expect(defaults).toEqual({ scheme: 'ProfileScheme' });

src/cli/register-tool-commands.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Argv } from 'yargs';
2+
import yargsParser from 'yargs-parser';
23
import type { ToolCatalog, ToolDefinition } from '../runtime/types.ts';
34
import type { OutputStyle } from '../types/common.ts';
45
import { DefaultToolInvoker } from '../runtime/tool-invoker.ts';
@@ -34,17 +35,15 @@ function buildXcodeIdeNoCommandsMessage(workflowName: string): string {
3435
}
3536

3637
function readProfileOverrideFromProcessArgv(): string | undefined {
37-
const argv = process.argv.slice(2);
38-
for (let index = 0; index < argv.length; index += 1) {
39-
const token = argv[index];
40-
if (token === '--profile') {
41-
return argv[index + 1];
42-
}
43-
if (token.startsWith('--profile=')) {
44-
return token.slice('--profile='.length);
45-
}
46-
}
47-
return undefined;
38+
const parsedArgv = yargsParser(process.argv.slice(2), {
39+
configuration: {
40+
'camel-case-expansion': true,
41+
},
42+
string: ['profile'],
43+
}) as { profile?: string | string[] };
44+
45+
const profile = parsedArgv.profile;
46+
return typeof profile === 'string' ? profile : undefined;
4847
}
4948

5049
/**

src/cli/session-defaults.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ export function resolveCliSessionDefaults(opts: {
2424
return { ...(opts.runtimeConfig.sessionDefaults ?? {}) };
2525
}
2626

27-
export function resolveActiveCliSessionDefaults(
28-
runtimeConfig: ResolvedRuntimeConfig,
29-
): Partial<SessionDefaults> {
30-
return resolveCliSessionDefaults({ runtimeConfig });
31-
}
32-
3327
export function isKnownCliSessionDefaultsProfile(
3428
runtimeConfig: ResolvedRuntimeConfig,
3529
profileName: string,

0 commit comments

Comments
 (0)