package me.coley.recaf.command.impl;

import me.coley.recaf.command.completion.FileCompletions;
import me.coley.recaf.mapping.*;
import org.objectweb.asm.ClassReader;
import org.tinylog.Logger;
import picocli.CommandLine;

import java.io.File;
import java.util.Map;
import java.util.concurrent.Callable;

/**
 * Command for applying mappings.
 *
 * @author Matt
 */
@CommandLine.Command(name = "remap", description = "Apply mappings to the workspace.")
public class Remap extends WorkspaceCommand implements Callable<Void> {
	@CommandLine.Parameters(index = "0",  description = "The mapping type.", arity = "0..1")
	public MappingImpl mapper = MappingImpl.SIMPLE;
	@CommandLine.Parameters(index = "1",  description = "The mapping file.",
			completionCandidates = FileCompletions.class)
	public File mapFile;

	/**
	 * @return n/a
	 *
	 * @throws Exception
	 * 		<ul><li>IllegalStateException, Invalid map file given</li></ul>
	 */
	@Override
	@SuppressWarnings("unchecked")
	public Void call() throws Exception {
		if(mapFile == null || !mapFile.isFile())
			throw new IllegalStateException("No mapping file provided!");
		// Apply
		Mappings mappings = mapper.create(mapFile);
		Map<String, byte[]> mapped = mappings.accept(workspace.getPrimary());
		// TODO: If the primary has a "META-INF/MANIFEST.MF" update the main class if renamed
		// Log
		StringBuilder sb = new StringBuilder("Classes updated: " + mapped.size());
		mapped.forEach((old, value) -> {
			ClassReader reader = new ClassReader(value);
			String rename = reader.getClassName();
			sb.append("\n - ").append(old);
			if (!old.equals(rename))
				sb.append(" => ").append(rename);
		});
		Logger.info(sb.toString());
		return null;
	}
}

@@ -801,16 +801,323 @@
 mapFile;
+%0A%09@CommandLine.Option(names = %22--noDebug%22, description = %22Clear debug info (variable names/generics).%22)%0A%09public boolean noDebug;%0A%09@CommandLine.Option(names = %22--allowLookup%22,%0A%09%09%09description = %22Allow hierarchy lookups for inheritance supported mapping.%22, defaultValue = %22true%22)%0A%09public boolean lookup = true;
 %0A%0A%09/**%0A%09
@@ -1479,16 +1479,142 @@
 pFile);%0A
+%09%09mappings.setClearDebugInfo(noDebug);%0A%09%09mappings.setCheckFieldHierarchy(lookup);%0A%09%09mappings.setCheckMethodHierarchy(lookup);%0A
 %09%09Map%3CSt

Add remapping updates to remap command