openAuthUrlWithStatus function

Future<void> openAuthUrlWithStatus({
  1. required String url,
  2. required bool launchBrowser,
  3. required Future<bool> openBrowserFn(
    1. String
    ),
  4. required void onStatus(
    1. String
    ),
  5. required String openedMessage,
  6. String skippedMessage = browserLaunchSkippedMessage,
})

Runs the browser-launch step shared by every OAuth/SSO CLI flow (gh-1450): prints the skip/opened/could-not-open status line, then ALWAYS the consistent authorization URL: line — the URL is a first-class output line in every outcome, because a launch that exited 0 says nothing about which browser (or whether any) opened. A throwing openBrowserFn degrades to the failure branch and still prints the URL.

openedMessage is the flow's success hint (kept verbatim from the pre-gh-1450 texts); skippedMessage overrides browserLaunchSkippedMessage.

Implementation

Future<void> openAuthUrlWithStatus({
  required String url,
  required bool launchBrowser,
  required Future<bool> Function(String) openBrowserFn,
  required void Function(String) onStatus,
  required String openedMessage,
  String skippedMessage = browserLaunchSkippedMessage,
}) async {
  var opened = false;
  if (launchBrowser) {
    try {
      opened = await openBrowserFn(url);
    } on Object {
      opened = false;
    }
  }
  if (!launchBrowser) {
    onStatus(skippedMessage);
  } else if (opened) {
    onStatus(openedMessage);
  } else {
    onStatus('could not open browser automatically');
  }
  onStatus('$authorizationUrlPrefix$url');
}