More shell fixes

This commit is contained in:
crschnick
2023-03-27 18:59:17 +00:00
parent 97079fb58d
commit 3ebe0d4639
6 changed files with 49 additions and 30 deletions
@@ -1,6 +1,5 @@
package io.xpipe.core.process;
import io.xpipe.core.util.FailableBiFunction;
import io.xpipe.core.util.FailableFunction;
import lombok.NonNull;
@@ -29,7 +28,7 @@ public abstract class ProcessControlProvider {
public static ShellControl createSub(
ShellControl parent,
@NonNull FailableFunction<ShellControl, String, Exception> commandFunction,
FailableBiFunction<ShellControl, String, String, Exception> terminalCommand) {
ShellControl.TerminalOpenFunction terminalCommand) {
return INSTANCES.stream()
.map(localProcessControlProvider ->
localProcessControlProvider.sub(parent, commandFunction, terminalCommand))
@@ -61,7 +60,7 @@ public abstract class ProcessControlProvider {
public abstract ShellControl sub(
ShellControl parent,
@NonNull FailableFunction<ShellControl, String, Exception> commandFunction,
FailableBiFunction<ShellControl, String, String, Exception> terminalCommand);
ShellControl.TerminalOpenFunction terminalCommand);
public abstract CommandControl command(
ShellControl parent,
@@ -1,6 +1,5 @@
package io.xpipe.core.process;
import io.xpipe.core.util.FailableBiFunction;
import io.xpipe.core.util.FailableFunction;
import io.xpipe.core.util.SecretValue;
import lombok.NonNull;
@@ -73,16 +72,53 @@ public interface ShellControl extends ProcessControl {
SecretValue getElevationPassword();
default ShellControl subShell(@NonNull ShellDialect type) {
return subShell(p -> type.getOpenCommand(), null).elevationPassword(getElevationPassword());
return subShell(p -> type.getOpenCommand(), new TerminalOpenFunction() {
@Override
public boolean changesEnvironment() {
return false;
}
@Override
public String prepare(ShellControl sc, String command) throws Exception {
return command;
}
}).elevationPassword(getElevationPassword());
}
interface TerminalOpenFunction {
boolean changesEnvironment();
String prepare(ShellControl sc, String command) throws Exception;
}
default ShellControl identicalSubShell() {
return subShell(p -> p.getShellDialect().getOpenCommand(), null)
return subShell(p -> p.getShellDialect().getOpenCommand(), new TerminalOpenFunction() {
@Override
public boolean changesEnvironment() {
return false;
}
@Override
public String prepare(ShellControl sc, String command) throws Exception {
return command;
}
})
.elevationPassword(getElevationPassword());
}
default ShellControl subShell(@NonNull String command) {
return subShell(processControl -> command, null);
return subShell(processControl -> command, new TerminalOpenFunction() {
@Override
public boolean changesEnvironment() {
return false;
}
@Override
public String prepare(ShellControl sc, String command) throws Exception {
return command;
}
});
}
default <T> T enforceDialect(@NonNull ShellDialect type, Function<ShellControl, T> sc) throws Exception {
@@ -97,7 +133,7 @@ public interface ShellControl extends ProcessControl {
ShellControl subShell(
FailableFunction<ShellControl, String, Exception> command,
FailableBiFunction<ShellControl, String, String, Exception> terminalCommand);
TerminalOpenFunction terminalCommand);
void executeLine(String command) throws Exception;
@@ -93,7 +93,7 @@ public interface ShellDialect {
String getOpenCommand();
String prepareTerminalInitFileOpenCommand(ShellControl parent, String file) throws Exception;
String prepareTerminalInitFileOpenCommand(ShellDialect parentDialect, ShellControl sc, String file) throws Exception;
String runScript(String file);