Skip to content

feat(query): add query command with structured JSON output#1612

Open
samuraisatoshi wants to merge 1 commit intoyonaskolb:masterfrom
samuraisatoshi:feat/query-command
Open

feat(query): add query command with structured JSON output#1612
samuraisatoshi wants to merge 1 commit intoyonaskolb:masterfrom
samuraisatoshi:feat/query-command

Conversation

@samuraisatoshi
Copy link
Copy Markdown

Summary

Adds a new xcodegen query command for introspecting the resolved project spec without generating a project. All output is pretty-printed JSON.

  • No side effects — read-only; never writes files or modifies state
  • Composable — JSON output pipes cleanly into jq, CI scripts, or editor integrations
  • Error-safe — missing target or missing --name returns {"error":"..."} with exit code 1

Query types (--type)

Type Description Requires
targets List all targets with name, type, platform
target Full detail for one target --name
sources Source paths for a target --name
settings Build settings for a target --name (optional --config)
dependencies Dependencies for a target --name

Output examples

xcodegen query --type targets

[
  { "name": "MyApp", "platform": "iOS", "type": "application" },
  { "name": "MyTests", "platform": "iOS", "type": "bundle.unit-test" }
]

xcodegen query --type target --name MyApp

{
  "dependencies": [{ "reference": "MyLib", "type": "target" }],
  "deploymentTarget": "16.0",
  "name": "MyApp",
  "platform": "iOS",
  "sources": ["Sources/App.swift"],
  "type": "application"
}

xcodegen query --type settings --name MyApp --config Debug

{
  "PRODUCT_BUNDLE_IDENTIFIER": "com.example.myapp",
  "SWIFT_VERSION": "5.9"
}

Use cases

  • CI: fail the build if a required target is missing, without running generate
  • Editor plugins: surface target list or build settings without parsing .xcodeproj
  • Scripting: xcodegen query --type sources --name MyApp | jq '.[]'
  • LLM agents: query structured project data for context without reading raw YAML

Test plan

  • xcodegen query → JSON array of all targets
  • xcodegen query --type target --name MyApp → full target detail
  • xcodegen query --type target --name Missing{"error":"..."}, exit 1
  • xcodegen query --type sources (missing --name) → {"error":"..."}, exit 1
  • xcodegen query --type settings --name MyApp --config Debug → config-specific settings
  • swift test passes

🤖 Generated with Claude Code

Adds a new `xcodegen query` command for introspecting the resolved
project spec without generating a project.

Query types (--type):
  targets      List all targets with name, type, platform
  target       Full detail for a single target (--name required)
  sources      Source paths for a target (--name required)
  settings     Build settings for a target (--name, optional --config)
  dependencies Dependencies for a target (--name required)

All output is pretty-printed JSON. Errors (target not found,
missing --name) are also reported as JSON with an 'error' key.
Exit code is 1 on error, 0 on success.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@yonaskolb
Copy link
Copy Markdown
Owner

We already have a xcodegen dump command. Does that fit your needs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants