命令
配置详细信息
本节详细介绍了扩展引入的配置设置,以增强或修改其行为。这些设置允许用户自定义扩展功能的各个方面。例如,修改二进制文件的路径,或更改性能设置。
package.json
示例
此示例说明了扩展的 package.json
中的配置设置的结构。它包括与扩展将管理或监控的环境和硬件资源相关的各种设置。
{
"contributes": {
"configuration": {
"title": "Podman",
"properties": {
"podman.binary.path": {
"type": "string",
"format": "file",
"default": "",
"description": "Custom path to Podman binary (Default is blank)"
},
"podman.machine.cpus": {
"type": "number",
"format": "cpu",
"minimum": 1,
"default": "HOST_HALF_CPU_CORES",
"maximum": "HOST_TOTAL_CPU",
"scope": "ContainerConnection",
"description": "CPU(s)"
}
}
}
}
}
在 TypeScript 代码中,您可以这样检索和使用配置
// Get configuration for this connection
const containerConfiguration = extensionApi.configuration.getConfiguration('podman', containerProviderConnection);
// Set a value
await containerConfiguration.update('machine.cpus', machineInfo.cpus);
// Get a value
await containerConfiguration.get('machine.cpus');
// Has a value
await containerConfiguration.has('machine.cpus');
JSON Schema
在 schema 中,您可以添加任何类型的 value,例如 "foo":"bar"
,可以像上面的 TypeScript 示例一样检索它。
{
"contributes": {
"configuration": {
"title": "string",
"properties": {
"string": {
"type": "string",
"default": "integer if type is integer, string if type is string, etc.",
"format": "string",
"minimum": "string or int",
"maximum": "string or int",
"description": "string",
"scope": "string or array, ex. ['DEFAULT', 'ONBOARDING']",
"hidden": "boolean",
"placeholder": "string",
"markdownDescription": "string",
"readonly": "boolean",
"enum": "array",
"step": "number",
"when": "string"
}
}
}
}
}
验证
要验证您的命令是否按预期工作
- 调整 package.json 中的配置设置
- 重新启动扩展或 Podman 桌面
- 在“设置”页面中验证更改。