Skip to content

Commit

Permalink
Merge pull request #783 from mittwald/feature/app-open
Browse files Browse the repository at this point in the history
Add "app open" command to quickly open an app installation in your browser
  • Loading branch information
martin-helmich authored Sep 12, 2024
2 parents d3add3b + 5907773 commit 544f334
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
20 changes: 20 additions & 0 deletions docs/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Manage apps, and app installations in your projects
* [`mw app install wordpress`](#mw-app-install-wordpress)
* [`mw app list`](#mw-app-list)
* [`mw app list-upgrade-candidates [INSTALLATION-ID]`](#mw-app-list-upgrade-candidates-installation-id)
* [`mw app open [INSTALLATION-ID]`](#mw-app-open-installation-id)
* [`mw app ssh [INSTALLATION-ID]`](#mw-app-ssh-installation-id)
* [`mw app uninstall [INSTALLATION-ID]`](#mw-app-uninstall-installation-id)
* [`mw app update [INSTALLATION-ID]`](#mw-app-update-installation-id)
Expand Down Expand Up @@ -1809,6 +1810,25 @@ DESCRIPTION
List upgrade candidates for an app installation.
```

## `mw app open [INSTALLATION-ID]`

Open an app installation in the browser.

```
USAGE
$ mw app open [INSTALLATION-ID]
ARGUMENTS
INSTALLATION-ID ID or short ID of an app installation; this argument is optional if a default app installation is set
in the context.
DESCRIPTION
Open an app installation in the browser.
This command opens an app installation in the browser. For this to work, there needs to be at least one virtual host
linked to the app installation.
```

## `mw app ssh [INSTALLATION-ID]`

Connect to an app via SSH
Expand Down
50 changes: 50 additions & 0 deletions src/commands/app/open.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { assertStatus } from "@mittwald/api-client-commons";
import open from "open";
import {
appInstallationArgs,
withAppInstallationId,
} from "../../lib/resources/app/flags.js";
import { ExtendedBaseCommand } from "../../lib/basecommands/ExtendedBaseCommand.js";
import buildAppURLsFromIngressList from "../../lib/resources/app/buildAppURLsFromIngressList.js";

export class Open extends ExtendedBaseCommand<typeof Open> {
static summary = "Open an app installation in the browser.";
static description =
"This command opens an app installation in the browser. For this to work, there needs to be at least one virtual host linked to the app installation.";

static args = { ...appInstallationArgs };

public async run(): Promise<void> {
const appInstallationId = await withAppInstallationId(
this.apiClient,
Open,
this.flags,
this.args,
this.config,
);
const installation = await this.apiClient.app.getAppinstallation({
appInstallationId,
});
assertStatus(installation, 200);

const domains = await this.apiClient.domain.ingressListIngresses({
queryParameters: {
projectId: installation.data.projectId,
},
});
assertStatus(domains, 200);

const urls = buildAppURLsFromIngressList(
domains.data,
installation.data.id,
);
if (urls.length === 0) {
throw new Error(
"This app installation is not linked to any virtual hosts.",
);
}

console.log("opening " + urls[0]);
await open(urls[0]);
}
}

0 comments on commit 544f334

Please sign in to comment.