package org.implab.gradle.common.exec;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.gradle.api.Action;

@NonNullByDefault
public class ShellTool {

    private final Shell shell;

    private final String executable;

    ShellTool(String executable, Shell shell) {
        this.shell = shell;
        this.executable = executable;
    }

    public ShellExec arguments(String... args) {
        return shell.create(CommandSpec.builder()
                .executable(executable)
                .arguments(args)
                .build());
    }

    public ShellExec arguments(Iterable<String> args) {
        return shell.create(CommandSpec.builder()
                .executable(executable)
                .arguments(args)
                .build());
    }

    public ShellExec arguments(Action<CommandArgumentsBuilder<?>> args) {
        var builder = CommandSpec.builder()
                .executable(executable);
        args.execute(builder);

        return shell.create(builder.build());
    }

}
