Files
docker-docs/content/reference/api/extensions-sdk/ExtensionHost.md
Allie Sadler bcc0a9c9a4 move extensions-sdk api content to reference (#20694)
* move extensions-sdk api content to reference

* review suggestion

* rename file
2024-08-23 14:41:17 +01:00

1.5 KiB

description, keywords, aliases
description keywords aliases
Docker extension API reference Docker, extensions, sdk, API, reference
/desktop/extensions-sdk/dev/api/reference/interfaces/ExtensionHost/
/extensions/extensions-sdk/dev/api/reference/interfaces/ExtensionHost/

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);
             },
           },
         });