@forge/cli
11.3.0-next.28-experimental-1aaebb011.3.0-next.32
out/command-line/register-containers-commands.jsout/command-line/register-containers-commands.js+165
Index: package/out/command-line/register-containers-commands.js
===================================================================
--- package/out/command-line/register-containers-commands.js
+++ package/out/command-line/register-containers-commands.js
@@ -0,0 +1,165 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.registerCommands = void 0;
+const cli_shared_1 = require("@forge/cli-shared");
+function parseContainersWithLatestTags(containers) {
+ return containers.map(({ key, repositoryURI, images }) => ({
+ key,
+ repositoryURI,
+ latestTags: images?.edges[0]?.node.tags.join(', ') || '-'
+ }));
+}
+const registerCreateContainerCommand = (parent, { ui, commands: { containerCommand } }) => {
+ parent
+ .command('create')
+ .description(cli_shared_1.Text.containers.create.cmd.desc)
+ .option('-k, --key [key]', cli_shared_1.Text.containers.create.cmd.keyOption)
+ .requireAppId()
+ .action(async ({ key }) => {
+ if (!key) {
+ ui.info(cli_shared_1.Text.containers.create.prompt.overview);
+ ui.emptyLine();
+ key = await ui.promptForText(cli_shared_1.Text.containers.create.prompt.entry);
+ ui.emptyLine();
+ }
+ ui.info(cli_shared_1.Text.containers.create.creatingNewContainer(key));
+ ui.info(cli_shared_1.Text.ctrlC);
+ ui.emptyLine();
+ const container = await ui.displayProgress(() => containerCommand.createContainer(key), cli_shared_1.Text.containers.create.start, cli_shared_1.Text.containers.create.success);
+ ui.emptyLine();
+ ui.info(cli_shared_1.Text.containers.create.createdRepositoryURI(container.repositoryURI));
+ });
+};
+const registerListContainersCommand = (parent, { ui, commands: { containerCommand } }) => {
+ parent
+ .command('list')
+ .description(cli_shared_1.Text.containers.list.cmd.desc)
+ .requireAppId()
+ .action(async () => {
+ ui.info(cli_shared_1.Text.containers.list.listingContainers);
+ ui.info(cli_shared_1.Text.ctrlC);
+ ui.emptyLine();
+ const containers = await containerCommand.fetchContainers();
+ ui.table([
+ ['key', 'Container Key'],
+ ['repositoryURI', 'Repository URI'],
+ ['latestTags', 'Latest Image Tag(s)']
+ ], parseContainersWithLatestTags(containers), { json: false, emptyMessage: cli_shared_1.Text.containers.list.noContainersFound });
+ });
+};
+const registerListImagesCommand = (parent, { ui, commands: { containerCommand } }) => {
+ parent
+ .command('images')
+ .requireAppId()
+ .description(cli_shared_1.Text.containers.images.cmd.desc)
+ .command('list')
+ .option('-k, --key [key]', cli_shared_1.Text.containers.images.list.cmd.keyOption)
+ .description(cli_shared_1.Text.containers.images.list.cmd.desc)
+ .action(async ({ key }) => {
+ if (!key) {
+ ui.info(cli_shared_1.Text.containers.images.list.prompt.overview);
+ ui.emptyLine();
+ key = await ui.promptForText(cli_shared_1.Text.containers.images.list.prompt.entry);
+ ui.emptyLine();
+ }
+ ui.info(cli_shared_1.Text.containers.images.list.listingImages(key));
+ ui.info(cli_shared_1.Text.ctrlC);
+ ui.emptyLine();
+ let startCursor;
+ do {
+ const { images, endCursor, hasNextPage } = await containerCommand.fetchImages(key, startCursor);
+ ui.table([
+ ['tags', 'Image Tags'],
+ ['pushedAt', 'Pushed At'],
+ ['lastPulledAt', 'Last Pulled At'],
+ ['sizeInBytes', 'Size (bytes)'],
+ ['digest', 'Digest']
+ ], images.map(({ digest, tags, pushedAt, lastPulledAt, sizeInBytes }) => ({
+ tags: tags.join(', '),
+ pushedAt,
+ digest,
+ lastPulledAt: lastPulledAt || '-',
+ sizeInBytes: sizeInBytes.toString()
+ })), { json: false, emptyMessage: cli_shared_1.Text.containers.images.list.noImagesFound });
+ startCursor = hasNextPage ? endCursor : undefined;
+ if (!startCursor) {
+ break;
+ }
+ ui.emptyLine();
+ const result = await ui.promptForText(cli_shared_1.Text.containers.images.list.promptNextPage);
+ if (result.toLowerCase() !== cli_shared_1.Text.containers.images.list.confirmationForNextPage) {
+ break;
+ }
+ } while (true);
+ });
+};
+const registerGetRepositoryLoginCommand = (parent, { ui, commands: { containerCommand } }) => {
+ parent
+ .command('get-login')
+ .description(cli_shared_1.Text.containers.login.cmd.desc)
+ .requireAppId()
+ .option('-pw, --password-only', cli_shared_1.Text.containers.login.cmd.onlyPassword)
+ .action(async (opts) => {
+ const login = await containerCommand.fetchLoginDetails();
+ if (opts.passwordOnly) {
+ ui.info(login.password);
+ }
+ else {
+ ui.table([
+ ['username', 'Username'],
+ ['password', 'Password'],
+ ['endpoint', 'Endpoint']
+ ], [
+ {
+ ...login,
+ password: cli_shared_1.Text.containers.login.truncatedPassword(login.password)
+ }
+ ]);
+ }
+ });
+};
+const registerDeleteContainerCommand = (parent, { ui, commands: { containerCommand } }) => {
+ parent
+ .command('delete')
+ .description(cli_shared_1.Text.containers.delete.cmd.desc)
+ .option('-k, --key [key]', cli_shared_1.Text.containers.delete.cmd.keyOption)
+ .requireAppId()
+ .action(async ({ key }) => {
+ if (!key) {
+ const containers = await containerCommand.fetchContainers();
+ if (!containers.length) {
+ ui.info(cli_shared_1.Text.containers.delete.interactive.noContainersFound);
+ return;
+ }
+ ui.info(cli_shared_1.Text.containers.delete.interactive.overview);
+ ui.emptyLine();
+ const selectedContainerIndex = await ui.promptForSingleChoiceTable(cli_shared_1.Text.containers.delete.interactive.desc, cli_shared_1.Text.containers.delete.interactive.progressInfo, ['Container Key', 'Repository URI', 'Latest Image Tag(s)'], parseContainersWithLatestTags(containers).map(({ key, repositoryURI, latestTags }) => ({
+ names: [key, repositoryURI, latestTags],
+ value: key,
+ primary: key
+ })));
+ key = containers[selectedContainerIndex].key;
+ ui.emptyLine();
+ }
+ ui.info(cli_shared_1.Text.containers.delete.deletingContainer(key));
+ ui.emptyLine();
+ ui.warn(cli_shared_1.Text.containers.delete.warning);
+ const confirmation = await ui.promptForText(cli_shared_1.Text.containers.delete.confirmation(key));
+ if (confirmation !== key) {
+ ui.info(cli_shared_1.Text.containers.delete.abortedDeletion);
+ return;
+ }
+ ui.info(cli_shared_1.Text.ctrlC);
+ ui.emptyLine();
+ await ui.displayProgress(() => containerCommand.deleteContainer(key), cli_shared_1.Text.containers.delete.start, cli_shared_1.Text.containers.delete.success);
+ });
+};
+const registerCommands = (deps) => {
+ const containersCmd = deps.cmd.command('containers', { hidden: true }).description(cli_shared_1.Text.containers.cmd.desc);
+ registerCreateContainerCommand(containersCmd, deps);
+ registerListContainersCommand(containersCmd, deps);
+ registerListImagesCommand(containersCmd, deps);
+ registerGetRepositoryLoginCommand(containersCmd, deps);
+ registerDeleteContainerCommand(containersCmd, deps);
+};
+exports.registerCommands = registerCommands;