Reputation: 1102
Is there a way to set a variable in a launch configuration, that comes from a file, without an extension?
I've seen the following:
${file}
But neither seems to allow me to use a variable of my own, from some external data. In my case, i just want to load a port from a json configuration, so i don't need to copy it into the launch configuration: "url": "http://something:${coolPeoplePort}"
. The server uses the port from that same file.
I've found this overly workflow specific way. This could potentially be abused, by running some program, that puts the variable on stdout. Why this feature is so specific to this application, i don't understand. It might work, because it seems to be precisely and only for putting ports into chrome debug URIs. Unlike the intention, the node program wouldn't be a webserver, and it would feel like i am using "happy hippo special case #5643", which is typically neither clean, future-proof, nor robust.
There are extensions that provide a multitude of ways to deal with this, but i don't want to install one, as it is a rather minor use case (i just don't want to copy some data to two places).
Upvotes: 1
Views: 610
Reputation: 28838
In extension Command Variable v1.10.0 I have added the possibility to extract a value from a JSON file.
Example config.json
file
{
"log": "foobar.log",
"server1": {
"port": 5011
},
"server2": {
"port": 5023
}
}
In your task.json
you want to use the server1 port value:
{
"version": "2.0.0",
"tasks": [
{
"label": "echo Server1Port",
"type": "shell",
"command": "echo",
"args": [
"${input:configServer1Port}"
],
"problemMatcher": []
}
],
"inputs": [
{
"id": "configServer1Port",
"type": "command",
"command": "extension.commandvariable.file.content",
"args": {
"fileName": "${workspaceFolder}/config.json",
"json": "content.server1.port",
"default": "4321"
}
}
]
}
Upvotes: 1