package org.implab.gradle.common.exec;

import java.util.concurrent.CompletableFuture;

import org.eclipse.jdt.annotation.NonNullByDefault;

import java.io.File;
import java.io.IOException;

/** Command line builder */
@NonNullByDefault
public interface ExecBuilder {

    /** Sets command line, clears previous one if any */
    void command(String cmd, String... args);

    /** Adds an argument to the command line */
    void argument(String arg);

    /** Sets the working directory */
    void directory(File directory);

    /**
     * Sets the environment value. The value cannot be null.
     * 
     * @param envVar The name of the environment variable
     * @param value The value to set, 
     */
    void setEnvironment(String envVar, String value);

    void unsetEnvironment(String envVar);

    /**
     * Sets redirection for the stdin, {@link RedirectFrom} will be applied
     * every time the process is started.
     * 
     * <p>If redirection 
     */
    void stdin(RedirectFrom from);

    /**
     * Sets redirection for the stdout, {@link RedirectTo} will be applied
     * every time the process is started.
     */
    void stdout(RedirectTo out);

    /**
     * Sets redirection for the stderr, {@link RedirectTo} will be applied
     * every time the process is started.
     */
    void stderr(RedirectTo err);

    /**
     * Creates and starts new process and returns {@link CompletableFuture}. The
     * process may be a remote process, or a shell process or etc.
     * @return
     * @throws IOException
     */
    CompletableFuture<Integer> start() throws IOException;

}
