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

@ -77,7 +77,7 @@ public class ScriptHelper {
if (toExecuteInShell != null) {
// Normalize line endings
content += String.join(nl, toExecuteInShell.lines().toList()) + nl;
content += nl + t.getExitCommand() + nl;
content += nl + t.getPassthroughExitCommand() + nl;
}
return createExecScript(t, processControl, t.initFileName(processControl), content);

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() {

View file

@ -9,9 +9,9 @@ Furthermore, the authentication options have been greatly expanded.
You can now supply both HTTP and SSH git URLs. If any input is required like a username/password/passphrase, XPipe will show a prompt.
If you chose to use an SSH git URL, you can also set key-based authentication options just as for other ssh connections.
Lastly, there is now a general data directory as well in which you can put any additional files like SSH keys that you want to include in the repository. You can then refer to them just as normal within XPipe but their file paths are automatically adapted on any system you clone the repository. You can open this data directory from the settings menu.
Lastly, there is now a general data directory as well in which you can put any additional files like SSH keys that you want to include in the repository. You can then refer to them just as normal within XPipe but their file paths are automatically adapted on any system you clone the repository to. You can open this data directory from the settings menu.
It is recommended to start with the git repository from scratch though to it properly fix past issues.
It is recommended to start with a remote git repository from scratch though to properly fix previous issues.
### Other changes