-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #783 from mittwald/feature/app-open
Add "app open" command to quickly open an app installation in your browser
- Loading branch information
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | ||
} | ||
} |