Rework command building and exit codes

This commit is contained in:
crschnick
2023-12-03 12:31:44 +00:00
parent 2b95ea5d6e
commit cb0cb97af3
7 changed files with 31 additions and 18 deletions

View File

@@ -0,0 +1,10 @@
package io.xpipe.core.process;
public interface CommandConfiguration {
String rawCommand();
String fullCommand(ShellControl shellControl) throws Exception;
CommandConfiguration withRawCommand(String newCommand);
}

View File

@@ -61,7 +61,7 @@ public interface CommandControl extends ProcessControl {
CommandControl withCustomCharset(Charset charset);
int getExitCode();
long getExitCode();
default CommandControl elevated(String message) {
return elevated(message, (v) -> true);

View File

@@ -14,7 +14,7 @@ public class ProcessOutputException extends Exception {
return new ProcessOutputException(message, ex.getExitCode(), ex.getOutput());
}
public static ProcessOutputException of(int exitCode, String... messages) {
public static ProcessOutputException of(long exitCode, String... messages) {
var combinedError = Arrays.stream(messages)
.filter(s -> s != null && !s.isBlank())
.map(s -> s.strip())
@@ -23,7 +23,7 @@ public class ProcessOutputException extends Exception {
var hasMessage = !combinedError.isBlank();
var errorSuffix = hasMessage ? ":\n" + combinedError : "";
var message =
switch (exitCode) {
switch ((int) exitCode) {
case CommandControl
.START_FAILED_EXIT_CODE -> "Process did not start up properly and had to be killed"
+ errorSuffix;
@@ -36,10 +36,10 @@ public class ProcessOutputException extends Exception {
return new ProcessOutputException(message, exitCode, combinedError);
}
private final int exitCode;
private final long exitCode;
private final String output;
private ProcessOutputException(String message, int exitCode, String output) {
private ProcessOutputException(String message, long exitCode, String output) {
super(message);
this.exitCode = exitCode;
this.output = output;

View File

@@ -140,7 +140,7 @@ public interface ShellControl extends ProcessControl {
}
}
ElevationResult buildElevatedCommand(String input, String prefix) throws Exception;
ElevationResult buildElevatedCommand(CommandConfiguration input, String prefix) throws Exception;
void restart() throws Exception;

View File

@@ -84,14 +84,6 @@ public interface ShellDialect {
return "cd \"" + directory + "\"";
}
default String getPushdCommand(String directory) {
return "pushd \"" + directory + "\"";
}
default String getPopdCommand() {
return "popd";
}
String getScriptFileEnding();
void addInlineVariablesToCommand(Map<String, String> variables, CommandBuilder command);
@@ -108,10 +100,21 @@ public interface ShellDialect {
sc.writeLine("exit");
}
default String getExitCommand() {
default String getPassthroughExitCommand() {
return "exit";
}
default String getNormalExitCommand() {
return "exit 0";
}
ElevationConfig determineElevationConfig(ShellControl shellControl) throws Exception;
ElevationResult elevateDumbCommand(ShellControl shellControl, CommandConfiguration command, String message) throws Exception;
String elevateTerminalCommand(ShellControl shellControl, String command, String message) throws Exception;
String environmentVariable(String name);
default String getConcatenationOperator() {