handle method

  1. @override
Future<int> handle(
  1. DowelContext ctx
)

Execute the command. Returns the process exit code.

Implementation

@override
Future<int> handle(DowelContext ctx) async {
  // 1. Resolve and parse the manifest.
  final manifestPath = await resolveManifestPath();
  if (manifestPath == null) {
    ctx.output.error(
      'magic_deeplink install.yaml could not be resolved. The plugin asset '
      'bundle is missing or the package was loaded from an unexpected location.',
    );
    return 1;
  }

  final InstallManifest manifest;
  try {
    manifest = ManifestParser.parseFile(manifestPath);
  } on FormatException catch (e) {
    ctx.output.error('install.yaml at $manifestPath: $e');
    return 1;
  } on ManifestValidationException catch (e) {
    ctx.output.error('install.yaml at $manifestPath: ${e.message}');
    return 1;
  }

  // 2. Build the install context and run the manifest installer.
  final installContext = buildContext(ctx);
  final installer = ManifestInstaller(installContext, manifest);
  final result = await installer.install(
    dryRun: isDryRun(ctx),
    force: isForce(ctx),
    nonInteractive: isNonInteractive(ctx),
  );

  // 3. Echo the post_install message on success.
  if (result is InstallSuccess && manifest.postInstall.message != null) {
    ctx.output.info(manifest.postInstall.message!);
  }

  if (result is InstallConflict) {
    ctx.output.error(
      'deeplink:install stopped on ${result.conflicts.length} conflicting '
      'file(s); review them, then re-run with --force.',
    );
  } else if (result is InstallError) {
    ctx.output.error('deeplink:install failed: ${result.error}');
  }

  return result is InstallSuccess || result is InstallDryRun ? 0 : 1;
}