handle method

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

Execute the command. Returns the process exit code.

Implementation

@override
Future<int> handle(ArtisanContext 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 Success && manifest.postInstall.message != null) {
    ctx.output.info(manifest.postInstall.message!);
  }

  return result is Success || result is DryRun ? 0 : 1;
}