function createBindAction()

in tools/awps-tunnel/server/commander.ts [138:203]


function createBindAction(bind: Command, settings: Settings, updated: BindCommandLineArgs, onDone: (updatedSettings: Settings) => void) {
  const endpoint = updated.endpoint;
  const hub = updated.hub;
  const upstream = updated.upstream;
  const subscription = updated.subscription;
  const resourceGroup = updated.resourceGroup;
  const webviewPort = updated.webviewPort;
  const webviewHost = updated.webviewHost;
  if (!endpoint && !hub && !upstream && !subscription && !resourceGroup && !webviewHost && !webviewPort) {
    printer.error("Error: Please specify at least one option to bind.");
    bind.outputHelp();
    return;
  }
  if (endpoint) {
    if (endpoint === true) {
      // the option to clear the endpoint
      settings.WebPubSub.Endpoint = undefined;
    } else {
      const parsed = parseUrl(endpoint, "https");
      if (!parsed) {
        printer.error(`Error: binding to invalid endpoint: ${endpoint}`);
        return;
      }
      settings.WebPubSub.Endpoint = parsed.toString();
    }
  }
  if (upstream) {
    if (upstream === true) {
      settings.WebPubSub.Upstream = undefined;
    } else {
      const parsed = parseUrl(upstream, "http");
      if (!parsed) {
        printer.error(`Error: binding to invalid upstream: ${upstream}`);
        return;
      }
      settings.WebPubSub.Upstream = parsed.toString();
    }
  }

  if (webviewHost) {
    if (webviewHost === true) {
      settings.WebPubSub.WebviewHost = undefined;
    } else {
      settings.WebPubSub.WebviewHost = webviewHost;
    }
  }

  if (webviewPort) {
    if (webviewPort === true) {
      settings.WebPubSub.WebviewPort = undefined;
    } else {
      settings.WebPubSub.WebviewPort = webviewPort;
    }
  }

  if (hub) {
    settings.WebPubSub.Hub = hub === true ? undefined : hub;
  }
  if (subscription) {
    settings.WebPubSub.SubscriptionId = subscription === true ? undefined : subscription;
  }
  if (resourceGroup) {
    settings.WebPubSub.ResourceGroup = resourceGroup === true ? undefined : resourceGroup;
  }
  onDone(settings);
}