From 853944d4893775d501afb44a38fd9144163289c5 Mon Sep 17 00:00:00 2001 From: Martin Helmich Date: Thu, 12 Sep 2024 08:15:11 +0200 Subject: [PATCH 1/2] Add "app open" command to quickly open an app installation in your browser --- src/commands/app/open.ts | 50 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/commands/app/open.ts diff --git a/src/commands/app/open.ts b/src/commands/app/open.ts new file mode 100644 index 00000000..15fff133 --- /dev/null +++ b/src/commands/app/open.ts @@ -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 { + 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 { + 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]); + } +} From d50528ba700dab170e88042289a58d7573daae4b Mon Sep 17 00:00:00 2001 From: martin-helmich Date: Thu, 12 Sep 2024 06:17:23 +0000 Subject: [PATCH 2/2] chore: re-generate README --- docs/app.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/app.md b/docs/app.md index fa3556aa..ad79407d 100644 --- a/docs/app.md +++ b/docs/app.md @@ -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) @@ -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