npm package diff

Package: @forge/cli

Versions: 10.13.6 - 11.0.0-next.18

File: package/out/command-line/command.js

Index: package/out/command-line/command.js
===================================================================
--- package/out/command-line/command.js
+++ package/out/command-line/command.js
@@ -1,7 +1,7 @@
 "use strict";
 Object.defineProperty(exports, "__esModule", { value: true });
-exports.getAutocompleteConfig = exports.Command = exports.WrapperError = void 0;
+exports.validateContext = exports.getAutocompleteConfig = exports.Command = exports.WrapperError = void 0;
 const tslib_1 = require("tslib");
 const commander_1 = tslib_1.__importStar(require("commander"));
 const semver_1 = tslib_1.__importDefault(require("semver"));
 const cli_shared_1 = require("@forge/cli-shared");
@@ -35,8 +35,9 @@
     cliDetails;
     credentialStore;
     defaultEnvironmentController;
     featureFlagService;
+    supportedProductsService;
     get verbose() {
         return this.cmd.opts().verbose;
     }
     static isError = (cmdError) => {
@@ -62,20 +63,21 @@
     requiresAuthentication;
     requiresAnalyticsConsent;
     requiredOptionFlags = [];
     preconditionFn = [];
-    static program(ui, analyticsClient, preCommandController, cliDetails, credentialStore, defaultEnvironmentController, featureFlagService) {
-        const cmd = new Command(ui, analyticsClient, preCommandController, cliDetails, credentialStore, defaultEnvironmentController, featureFlagService, {});
+    static program(ui, analyticsClient, preCommandController, cliDetails, credentialStore, defaultEnvironmentController, featureFlagService, supportedProductsService) {
+        const cmd = new Command(ui, analyticsClient, preCommandController, cliDetails, credentialStore, defaultEnvironmentController, featureFlagService, supportedProductsService, {});
         return cmd.version(cliDetails?.version ?? 'unknown', '--version').option('--verbose', cli_shared_1.Text.optionVerbose);
     }
-    constructor(ui, analyticsClient, preCommandController, cliDetails, credentialStore, defaultEnvironmentController, featureFlagService, { cmd, analyticsName, requiresAuthentication, requiresAnalyticsConsent, requiredOptionFlags, preconditionFn }) {
+    constructor(ui, analyticsClient, preCommandController, cliDetails, credentialStore, defaultEnvironmentController, featureFlagService, supportedProductsService, { cmd, analyticsName, requiresAuthentication, requiresAnalyticsConsent, requiredOptionFlags, preconditionFn }) {
         this.ui = ui;
         this.analyticsClient = analyticsClient;
         this.preCommandController = preCommandController;
         this.cliDetails = cliDetails;
         this.credentialStore = credentialStore;
         this.defaultEnvironmentController = defaultEnvironmentController;
         this.featureFlagService = featureFlagService;
+        this.supportedProductsService = supportedProductsService;
         this.cmd = cmd || new commander_1.default.Command();
         this.analyticsName = analyticsName;
         this.requiresAuthentication = requiresAuthentication ?? true;
         this.requiresAnalyticsConsent = requiresAnalyticsConsent ?? true;
@@ -89,9 +91,9 @@
         });
         this.cmd.configureHelp({ sortSubcommands: true });
     }
     clone(overrides) {
-        return new Command(this.ui, this.analyticsClient, this.preCommandController, this.cliDetails, this.credentialStore, this.defaultEnvironmentController, this.featureFlagService, {
+        return new Command(this.ui, this.analyticsClient, this.preCommandController, this.cliDetails, this.credentialStore, this.defaultEnvironmentController, this.featureFlagService, this.supportedProductsService, {
             cmd: this.cmd,
             analyticsName: this.analyticsName,
             requiresAuthentication: this.requiresAuthentication,
             requiresAnalyticsConsent: this.requiresAnalyticsConsent,
@@ -108,9 +110,9 @@
         const cmd = this.cmd
             .command(name, opts)
             .allowUnknownOption(false)
             .allowExcessArguments(false);
-        const subCommand = new Command(this.ui, this.analyticsClient, this.preCommandController, this.cliDetails, this.credentialStore, this.defaultEnvironmentController, this.featureFlagService, {
+        const subCommand = new Command(this.ui, this.analyticsClient, this.preCommandController, this.cliDetails, this.credentialStore, this.defaultEnvironmentController, this.featureFlagService, this.supportedProductsService, {
             cmd,
             analyticsName: Command.concatenateNames(this.analyticsName, cmd.name())
         }).option('--verbose', cli_shared_1.Text.optionVerbose);
         return subCommand;
@@ -175,8 +177,17 @@
             const environment = environmentArg || (await this.defaultEnvironmentController.run(nonInteractive));
             return { environment: (0, environment_1.checkEnvironmentOption)(environment) };
         });
     }
+    contextOption(supportedProducts) {
+        const supportedProductsService = this.supportedProductsService;
+        return this.option('-s, --site [site]', cli_shared_1.Text.optionSite)
+            .option('-p, --product [product]', cli_shared_1.Text.optionProduct(supportedProducts))
+            .precondition(async (...args) => {
+            const { site, product } = last(args);
+            return await validateContext({ supportedProductsService, site, product });
+        });
+    }
     jsonOption() {
         return this.option('--json', cli_shared_1.Text.optionJson, false);
     }
     requireNoAuthentication() {
@@ -415,4 +426,16 @@
     const options = getOptionsData(cmd);
     return { commands, options };
 }
 exports.getAutocompleteConfig = getAutocompleteConfig;
+async function validateContext({ supportedProductsService, site, product }) {
+    let maybeSupportedProduct = undefined;
+    let maybeSiteUrl = undefined;
+    if (product !== undefined) {
+        maybeSupportedProduct = await supportedProductsService.validateSupportedProduct(product);
+    }
+    if (site) {
+        maybeSiteUrl = await supportedProductsService.validateSite(site, maybeSupportedProduct);
+    }
+    return { site: maybeSiteUrl, product: maybeSupportedProduct };
+}
+exports.validateContext = validateContext;