mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-04-24 16:40:58 -04:00
Rework command building and exit codes
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
package io.xpipe.core.process;
|
||||
|
||||
public interface CommandConfiguration {
|
||||
|
||||
String rawCommand();
|
||||
|
||||
String fullCommand(ShellControl shellControl) throws Exception;
|
||||
|
||||
CommandConfiguration withRawCommand(String newCommand);
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user