package org.implab.gradle.common.exec;

import java.util.stream.Stream;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.implab.gradle.common.utils.Values;

@NonNullByDefault
public interface CommandBuilder {

    CommandBuilder executable(String executable);

    default CommandBuilder commandLine(String executable, String... args) {
        return executable(executable)
            .arguments(args);
    }

    default CommandBuilder arg(String arg0, String... args) {
        return arguments(() -> Stream
                .concat(Stream.of(arg0), Stream.of(args))
                .iterator());
    }

    default CommandBuilder arguments(String... args) {
        return arguments(Values.iterable(args));
    }

    CommandBuilder arguments(Iterable<String> args);

    default CommandBuilder from(CommandSpec commandSpec) {
        return executable(commandSpec.executable())
                .arguments(commandSpec.arguments());
    }
}
