package ahlers.phantom.embedded;

import com.google.common.collect.ImmutableList;
import de.flapdoodle.embed.process.distribution.IVersion;
import de.flapdoodle.embed.process.extract.IExtractedFileSet;

import java.io.IOException;
import java.util.List;

import static java.lang.String.format;

/**
 * @author [[mailto:michael@ahlers.consulting Michael Ahlers]]
 */
public enum PhantomCommand
        implements IPhantomCommand {

    Any {
        @Override
        public boolean matches(final IVersion version) {
            return true;
        }

        @Override
        public List<String> emit(final PhantomConfig config, final IExtractedFileSet files) throws IOException {
            return ImmutableList
                    .<String>builder()
                    .add(format("--debug=%s", config.getDebug()))
                    .build();
        }
    },

    V21 {
        @Override
        public boolean matches(final IVersion version) {
            return PhantomVersion.V211 == version;
        }

        @Override
        public List<String> emit(PhantomConfig config, IExtractedFileSet exe) throws IOException {
            return ImmutableList
                    .<String>builder()
                    .addAll(Any.emit(config, exe))
                    .build();
        }
    };

    /**
     * {@link PhantomCommand#Any} is guaranteed to match.
     */
    private static IPhantomCommand valueFor(final IVersion version) {
        for (final IPhantomCommand emitter : values()) {
            if (emitter.matches(version)) {
                return emitter;
            }
        }

        return Any;
    }

}

@@ -75,16 +75,78 @@
 leList;%0A
+import de.flapdoodle.embed.process.distribution.Distribution;%0A
 import d
@@ -1442,14 +1442,13 @@
    p
-rivate
+ublic
  sta
@@ -1687,10 +1687,147 @@
 %0A    %7D%0A%0A
+    public static IPhantomCommand valueFor(final Distribution distribution) %7B%0A        return valueFor(distribution.getVersion());%0A    %7D%0A%0A
 %7D%0A

Add convenience factory