Skip to content
This repository has been archived by the owner on Jun 13, 2021. It is now read-only.

Run command as variable #27

Closed
giantmustache opened this issue Jul 18, 2019 · 2 comments
Closed

Run command as variable #27

giantmustache opened this issue Jul 18, 2019 · 2 comments
Labels
good first issue Good for newcomers question Further information is requested

Comments

@giantmustache
Copy link

I see the use of these custom commands and I would like to use it in my launch.json as a variable like so "cd ${command:ego.power-tools.commands.my_command}"

With a command that actually has a return statement:

// my_command.js
exports.execute = async (args) => {
    return "hello"
};

Would something like that be possible with these power tools?

@ghost
Copy link

ghost commented Jul 18, 2019

@giantmustache

You can realize it the following way:

.vscode/settings.json (register command myCommand, which is executed via my_command.js):

{
    "ego.power-tools": {
        "commands": {
            "myCommand": {
                "script": "my_command.js"
            }
        }
    }
}

.vscode/my_command.js (return a string in execute(), which replaces ${command:myCommand}, s. below):

exports.execute = async (args) => {
    return "hello"
};

.vscode/launch.json (define ${command:myCommand}, which is replaces by the result of execute() from my_command.js):

// A launch configuration that compiles the extension and then opens it inside a new window
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "myCommand Test",
            "type": "node",
            "request": "launch",
            "args": ["${command:myCommand}"]
        }
    ]
}

@giantmustache
Copy link
Author

giantmustache commented Jul 18, 2019

This is exactly what I was looking for! Thank you for the fast response.

@ghost ghost added good first issue Good for newcomers question Further information is requested labels Jul 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Good for newcomers question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant