Home > OS >  Split ${fileBasename} in VS Code task
Split ${fileBasename} in VS Code task

Time:10-06

I am trying to automate a curl command in a VS Code task.

The full curl command without headers and auth should look something like:

curl -X PUT http://localhost:9000/schema/schemaName -d @schemaName-schema.json

Currently my task command looks like this:

curl -X PUT http://localhost:9000/schema/${fileBasename} -d @${fileBasename}

And fileBasename would be schemaName-schema.json

I want to split the fileBasename on the dash -, is this possible inside the VS Code command syntax?

CodePudding user response:

You can try if the snippet variable find replace also works for task variables

${fileBasename/^(. ?)-.*$/$1/}

Or you can use the extension Command Variable

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "echo some var",
      "type": "shell",
      "command": "curl -X PUT http://localhost:9000/schema/${input:fileBasenamePart} -d @${fileBasename}",
      "problemMatcher": []
    }
  ],
  "inputs": [
    {
      "id": "fileBasenamePart",
      "type": "command",
      "command": "extension.commandvariable.transform",
      "args": {
        "text": "${fileBasename}",
        "find": "^(. ?)-.*$",
        "replace": "$1"
      }
    }
  ]
}
  • Related