跳到主要内容

开发 · 命令参考

qzx formatCode

作用

检测语言并对源代码文件运行相应的格式化工具。

命令成熟度:Alpha

可用于真实使用和反馈,但其接口与行为仍可能继续演进。 这是当前开发 checkout 的评估。未来每个不可变发布标签都会保留该版本中包含的准确评估。 可在 PyPI 0.2.2.0.9 使用。文档对应 alpha checkout 0.2.2.0.9。

行为与内置保护

实际模式会应用你请求的更改

提供预览

需要时使用原生工具

无需网络即可运行

使用你当前的权限;结果可能有所不同

模拟仅检查格式化工具的结果,不需要备份。真实格式化只有在为所选文件或目录创建可恢复备份后,才会调用本地已安装工具。

QZX 会在实际更改前创建恢复文件;只有在你明确决定故意跳过它时才使用 --dangerously-bypass-approvals-and-sandbox/--yolo。

此安全分类由 OpenAI GPT-5.6 Pro 于 2026-08-25 对照实现摘要 sha256:8e1da26751942fe10264195b83fc29c5259e48eab9c7b2cf70717a0ed2ac665f 审阅。

准确语法

qzx formatCode <path> [language] [dry_run] --json

参数

滑动或使用横向滚动条查看所有列。

名称类型必填默认值描述
pathstr未声明要格式化的文件或目录
languagestr""强制指定语言(python、javascript、typescript、rust、go、php、c 或 cpp)。默认自动检测。
dry_runboolfalse在不写入文件的情况下检查是否会发生更改(true/false)

输入示例

qzx formatCode src/

格式化 src/ 中所有受支持的源文件

qzx formatCode src/main.py

使用 black 格式化单个 Python 文件

qzx formatCode src/ python

仅格式化 src/ 中的 Python 文件

qzx formatCode src/ --dry-run

模拟格式化以查看哪些文件会改变

要获得完整结构化载荷,请添加 --json: qzx formatCode <path> [language] [dry_run] --json

代表性输出示例

此示意 JSON 源自当前实现所支持的结果契约。它展示命令可能返回的内容,并不声称这是录制的实际执行;具体值会随输入、设备、权限和可选工具而变化。

示例命令: qzx formatCode src/ --json

{
    "success": true,
    "message": "Formats source code files by auto-detecting language and invoking the right formatter. In this illustrative example, the command completed successfully.",
    "meta": {
        "command": "formatCode",
        "command_maturity": {
            "stage": "alpha",
            "label": "Alpha",
            "sequence": 2,
            "public_executable": true,
            "stability": "interface_may_change",
            "summary": "Available for real use and feedback while its interface and behavior can still evolve.",
            "promotion_review_required": false,
            "assessment_scope": "development_checkout"
        },
        "duration_ms": 0,
        "schema_version": 1
    },
    "all_succeeded": true,
    "dry_run": true,
    "failed": [
        "Example value"
    ],
    "failed_count": 3,
    "formatted": [
        "Example value"
    ],
    "formatted_count": 3,
    "path": "C:\\project\\example.txt",
    "skipped": [
        "Example value"
    ],
    "skipped_count": 3,
    "total_files": 3,
    "unavailable_tools": []
}
查看 JSON 结果契约
{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "required": [
        "success",
        "message",
        "meta"
    ],
    "properties": {
        "success": {
            "type": "boolean"
        },
        "message": {
            "type": "string"
        },
        "meta": {
            "type": "object",
            "required": [
                "command",
                "command_maturity",
                "duration_ms",
                "schema_version"
            ],
            "properties": {
                "command": {
                    "type": "string"
                },
                "command_maturity": {
                    "type": "object",
                    "required": [
                        "stage",
                        "label",
                        "sequence",
                        "public_executable",
                        "stability",
                        "summary",
                        "promotion_review_required",
                        "assessment_scope"
                    ],
                    "properties": {
                        "stage": {
                            "type": "string"
                        },
                        "label": {
                            "type": "string"
                        },
                        "sequence": {
                            "type": "integer"
                        },
                        "public_executable": {
                            "type": "boolean"
                        },
                        "stability": {
                            "type": "string"
                        },
                        "summary": {
                            "type": "string"
                        },
                        "promotion_review_required": {
                            "type": "boolean"
                        },
                        "assessment_scope": {
                            "type": "string"
                        },
                        "note": {
                            "type": "string"
                        },
                        "review": {
                            "type": "object",
                            "required": [
                                "reviewed_on",
                                "rationale",
                                "evidence"
                            ],
                            "properties": {
                                "reviewed_on": {
                                    "type": "string",
                                    "format": "date"
                                },
                                "rationale": {
                                    "type": "string"
                                },
                                "evidence": {
                                    "type": "array",
                                    "minItems": 1,
                                    "items": {
                                        "type": "string"
                                    }
                                },
                                "replacement": {
                                    "type": "string"
                                }
                            },
                            "additionalProperties": false
                        }
                    },
                    "additionalProperties": true
                },
                "duration_ms": {
                    "type": "number"
                },
                "schema_version": {
                    "type": "integer"
                }
            },
            "additionalProperties": true
        },
        "all_succeeded": {
            "type": "boolean"
        },
        "dry_run": [],
        "error": {
            "type": "string"
        },
        "failed": {
            "type": "array"
        },
        "failed_count": {
            "type": "integer"
        },
        "formatted": {
            "type": "array"
        },
        "formatted_count": {
            "type": "integer"
        },
        "path": [],
        "skipped": {
            "type": "array"
        },
        "skipped_count": {
            "type": "integer"
        },
        "total_files": {
            "type": "integer"
        },
        "unavailable_tools": {
            "type": "array"
        }
    },
    "additionalProperties": true
}

错误与限制

公开契约要求失败时返回 success=false 和具有描述性的 message。此目录尚未为每个命令声明专门的错误分类;请检查结果,不要推断不存在的错误码。

QZX 仍处于 alpha 阶段。可选依赖、权限和主机能力可能影响结果。

证据流程:需要受控的特权环境。

证据与来源

文档渠道
开发文档 0.2.2.0.9 · main · sha256:cfba936e39931c286ca23add0ae546693db17d8b316e7cbc3891d26642d9b7e8
可用性
0.2.2.0.9 或更早

继续探索

这些命令同样属于 开发 类别。对比它们,选择最适合解决任务的操作。

浏览所有 QZX 命令