Fix scripts not applying

This commit is contained in:
crschnick
2024-05-10 08:15:01 +00:00
parent 7507f664df
commit 620c30382f
9 changed files with 105 additions and 138 deletions

View File

@@ -1,35 +0,0 @@
package io.xpipe.core.process;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
public interface ScriptSnippet {
String content(ShellControl shellControl);
ExecutionType executionType();
@Getter
enum ExecutionType {
@JsonProperty("dumbOnly")
DUMB_ONLY("dumbOnly"),
@JsonProperty("terminalOnly")
TERMINAL_ONLY("terminalOnly"),
@JsonProperty("both")
BOTH("both");
private final String id;
ExecutionType(String id) {
this.id = id;
}
public boolean runInDumb() {
return this == DUMB_ONLY || this == BOTH;
}
public boolean runInTerminal() {
return this == TERMINAL_ONLY || this == BOTH;
}
}
}

View File

@@ -30,7 +30,7 @@ public interface ShellControl extends ProcessControl {
ShellControl withSourceStore(ShellStore store);
List<ScriptSnippet> getInitCommands();
List<ShellInitCommand> getInitCommands();
ParentSystemAccess getParentSystemAccess();
@@ -173,7 +173,7 @@ public interface ShellControl extends ProcessControl {
ShellControl elevated(ElevationFunction elevationFunction);
ShellControl withInitSnippet(ScriptSnippet snippet);
ShellControl withInitSnippet(ShellInitCommand snippet);
default ShellControl subShell(@NonNull ShellDialect type) {
var o = new ShellOpenFunction() {

View File

@@ -0,0 +1,69 @@
package io.xpipe.core.process;
import lombok.NonNull;
import java.util.Optional;
public interface ShellInitCommand {
default void runDumb(ShellControl shellControl) throws Exception {
throw new UnsupportedOperationException();
}
default Optional<String> terminalContent(ShellControl shellControl) throws Exception {
throw new UnsupportedOperationException();
}
default boolean runInDumb() {
return false;
}
default boolean runInTerminal() {
return false;
}
interface Terminal extends ShellInitCommand {
Optional<String> terminalContent(ShellControl shellControl) throws Exception;
default boolean runInTerminal() {
return true;
}
}
class Simple implements ShellInitCommand {
@NonNull
private final String content;
private final boolean dumb;
private final boolean terminal;
public Simple(@NonNull String content, boolean dumb, boolean terminal) {
this.content = content;
this.dumb = dumb;
this.terminal = terminal;
}
@Override
public void runDumb(ShellControl shellControl) throws Exception {
shellControl.executeSimpleCommand(content);
}
@Override
public Optional<String> terminalContent(ShellControl shellControl) throws Exception {
return Optional.of(content);
}
@Override
public boolean runInDumb() {
return dumb;
}
@Override
public boolean runInTerminal() {
return terminal;
}
}
}

View File

@@ -1,27 +0,0 @@
package io.xpipe.core.process;
import lombok.NonNull;
public class SimpleScriptSnippet implements ScriptSnippet {
@NonNull
private final String content;
@NonNull
private final ExecutionType executionType;
public SimpleScriptSnippet(@NonNull String content, @NonNull ExecutionType executionType) {
this.content = content;
this.executionType = executionType;
}
@Override
public String content(ShellControl shellControl) {
return content;
}
@Override
public ExecutionType executionType() {
return executionType;
}
}