package org.implab.gradle.common.exec;

import java.io.IOException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;

public interface Executable {
    CompletableFuture<Integer> exec() throws IOException;

    /** Starts process and will throw error if error code is non-zero */
    default CompletableFuture<Void> execChecked() throws IOException {
        return exec().thenAccept(code -> {
            if (code != 0)
            throw new CompletionException(new IOException(
                    String.format("The process is terminated with code %d", code)));
        });
    }
}
