Joel
Joel

Reputation: 6183

Conditional tasks in visual studio code

I'm trying to create an hierarchical task structure. Since this project has over 100tasks as of now, we need to simplify its structure by using "sub-tasks" or inputs as its called in vs code to gain more visibility over our tasks.

Consider this example (code provided below for this):

Run Task -> option(s) --> sub-options 
            option    --> sub-options

What I would ideally want is:

Run "myTask" -> option(s) --> sub-options based on previous
                          |
                          |--> sub-options based on previous
                          | 
                          |--> sub-options based on previous

Lets say I choose Run Task -> Option1 -> avaliable sub-options for option1

I want to conditionally see the options for the "parent".

A real world scenario:

[Build Customer] Task -> CustomerName  -> Avaliable products for customer
                      -> CustomerName2 -> Avaliable products for customer2

tasks.json

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "myTask",
      "type": "shell",
      "command": ".\\AutoBuild.bat",
      "options": {
        "shell": {
          "executable": "powershell.exe"
        },
        "cwd": "${workspaceFolder}",
      },
      "args": [
        "${input:myArg1}",
        "${input:myArg2}"
      ], 
      "group": "build",
      "problemMatcher": []
    }
  ],
  "inputs": [
    {
      "type": "pickString",
      "id":"myArg1",
      "options": [
        "option1",
        "option2",
        "option3",
        "option4"
      ],
      "description": "myArg1",
      "default": ""
    },
    {
      "type": "pickString",
      "id":"myArg2",
      "description": "myArg2",
      "options": [
        "sub-option1",
        "sub-option2",
        "sub-option3",
        "sub-option4"
      ],
      "default": ""
    },
  ]
}

Is this possible to achieve somehow?

Ugly or proof of concept solutions are welcome!

Upvotes: 5

Views: 3870

Answers (1)

Robert Brisita
Robert Brisita

Reputation: 5844

Unfortunately there are no conditional properties for extensions like keybindings' "when". The work around is to execute a script file where input can be acted on. For instance:

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "myTask",
      "type": "shell",
      "command": ".\\AutoBuild.bat",
      "args": [
        "${input:myArg1}",
        "${input:myArg2}"
      ]
    }
  ]
}

AutoBuild.bat would then have logic to test and act on myArg1 and myArg2.

Upvotes: 1

Related Questions