5

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!

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

This is unfortunately not an answer to the question.
There is value in knowing that one cannot do conditionals within tasks.json.
I mean, what you're suggesting in terms of code, i've already provided.
Fair statement. I guess this just confirms that tasks shouldn't be doing too much.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.