visual-studio-code - 在 vscode 任务中处理来自输入用户的多个值
问题描述
然后根据选择的选项在inputs
vscode中接收用户输入以处理多个值的最佳解决方案是什么?tasks.json
有没有像下面这样的解决方案?
{
"version": "2.0.0",
"inputs": [
{
"id": "selectProject",
"type": "pickString",
"description": "Some decription",
"options":
[
{
"label": "project1",
"value" : {"path":"","name":"","link":"","anyOther":""} // something like this
} ,
{
"label": "project2",
"value" : {"path":"","name":"","link":"","anyOther":""} // something like this
}
]
}
],
"tasks": [
{
"label": "test on projects",
"type": "process",
"command": "echo",
"args": [
"${input:selectProject.path}", // handle many info from one chosen option
"${input:selectProject.name}",
"${input:selectProject.link}",
"${input:selectProject.anyOther}"
]
}
]
}
当前选项只能接收一个值:(
"options":
[
{ "label": "project1", "value" : "value" } ,
{ "label": "project2", "value" : "value" }
]
解决方案
您可以使用扩展命令变量v1.22.0。
该命令extension.commandvariable.pickStringRemember
可以记住 1 个选择的多个值。
label-value 的语法有点不同,因为我不知道pickString
支持它。
{
"version": "2.0.0",
"tasks": [
{
"label": "Do some project",
"type": "process",
"command": "echo",
"args": [
"${input:selectProject.path}",
"${input:selectProject.name}",
"${input:selectProject.link}",
"${input:selectProject.anyOther}"
],
"problemMatcher": []
}
],
"inputs": [
{
"id": "selectProject.path",
"type": "command",
"command": "extension.commandvariable.pickStringRemember",
"args": {
"key": "path",
"options": [
["project1", {"path":"p1","name":"n1","link":"lnk1","anyOther":"any1"}],
["project2", {"path":"p2","name":"n2","link":"lnk2","anyOther":"any2"}]
],
"description": "Pick a project"
}
},
{
"id": "selectProject.name",
"type": "command",
"command": "extension.commandvariable.rememberPick",
"args": { "key": "name" }
},
{
"id": "selectProject.link",
"type": "command",
"command": "extension.commandvariable.rememberPick",
"args": { "key": "link" }
},
{
"id": "selectProject.anyOther",
"type": "command",
"command": "extension.commandvariable.rememberPick",
"args": { "key": "anyOther" }
}
]
}
推荐阅读
- python - Python smtplib 主题在函数内部不起作用
- c# - 初始数据库迁移:没有为此 DbContext 配置数据库提供程序
- c++ - 如何使用 C++ 通过 HTTP 协议上传文件?
- android - 如何生成安卓关机充电动画中使用的字体图片?
- .net - MAC - 错误 MSB3644:.NETFramework,Version=v4.7.2 的参考程序集未找到
- sql - 通过加入另一个表来更新历史数据
- java - 如何从 Android Studio 中的倒数计时器返回标志数组的值?
- outlook - 如何使用 Graph API 获取电子邮件附件的嵌套附件?
- mysql - 递归选择表
- python - 如何与 Tkinter 的 while 循环并行运行代码?