Files
docker-docs/desktop/extensions-sdk/dev/api/reference/interfaces/ExtensionHost.md
Guillaume Tardif efb9ca8caf Extension sdk update (#15687)
* Update extension SDK with new APIs for exec with ENV vars and CWD

Signed-off-by: Guillaume Tardif <guillaume.tardif@gmail.com>

* Update extension SDK with new APIs for exec with ENV vars and CWD

Signed-off-by: Guillaume Tardif <guillaume.tardif@gmail.com>

Signed-off-by: Guillaume Tardif <guillaume.tardif@gmail.com>
2022-09-20 09:46:44 +01:00

1.4 KiB

description, keywords, skip_read_time
description keywords skip_read_time
Docker extension API reference Docker, extensions, sdk, API, reference true

Interface: ExtensionHost

since 0.2.0

Properties

cli

Readonly cli: ExtensionCli

Executes a command in the host.

For example, execute the shipped binary kubectl -h command in the host:

await ddClient.extension.host.cli.exec("kubectl", ["-h"]);

Streams the output of the command executed in the backend container or in the host.

Provided the kubectl binary is shipped as part of your extension, you can spawn the kubectl -h command in the host:

await ddClient.extension.host.cli.exec("kubectl", ["-h"], {
           stream: {
             onOutput(data): void {
                 // As we can receive both `stdout` and `stderr`, we wrap them in a JSON object
                 JSON.stringify(
                   {
                     stdout: data.stdout,
                     stderr: data.stderr,
                   },
                   null,
                   "  "
                 );
             },
             onError(error: any): void {
               console.error(error);
             },
             onClose(exitCode: number): void {
               console.log("onClose with exit code " + exitCode);
             },
           },
         });