Shell handling improvements

This commit is contained in:
crschnick
2023-03-17 04:52:57 +00:00
parent 1230a22969
commit ae2b7289cc
10 changed files with 40 additions and 123 deletions
@@ -13,6 +13,12 @@ import java.util.stream.Stream;
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
public interface ShellDialect {
String argument(String s);
default String applyRcFileCommand() {
return null;
}
CommandControl createStreamFileWriteCommand(ShellControl shellControl, String file);
default String getCdCommand(String directory){
@@ -53,8 +59,6 @@ public interface ShellDialect {
return "exit";
}
String getExitCodeVariable();
String environmentVariable(String name);
default String getConcatenationOperator() {
@@ -67,7 +71,7 @@ public interface ShellDialect {
String getMakeExecutableCommand(String file);
default String getScriptEchoCommand(String s) {
default String getSelfdeleteScriptEchoCommand(String s) {
return getEchoCommand(s, false);
}
@@ -85,15 +89,11 @@ public interface ShellDialect {
String getNormalOpenCommand();
String getInitFileOpenCommand(String file);
String prepareInitFileOpenCommand(ShellControl parent, String file);
String executeCommandWithShell(String cmd);
List<String> executeCommandListWithShell(String cmd);
List<String> executeCommandListWithShell(List<String> cmd);
List<String> getMkdirsCommand(String dirs);
String getMkdirsCommand(String dirs);
String getFileReadCommand(String file);
@@ -121,7 +121,5 @@ public interface ShellDialect {
String getDisplayName();
String getExecutable();
boolean doesRepeatInput();
boolean doesEchoInput();
}
@@ -12,6 +12,7 @@ public class ShellDialects {
public static ShellDialect POWERSHELL;
public static ShellDialect CMD;
public static ShellDialect SH;
public static ShellDialect DASH;
public static ShellDialect BASH;
public static ShellDialect ZSH;
@@ -26,6 +27,7 @@ public class ShellDialects {
CMD = byName("cmd");
POWERSHELL = byName("powershell");
SH = byName("sh");
DASH = byName("dash");
BASH = byName("bash");
ZSH = byName("zsh");
}
@@ -107,8 +107,7 @@ public class ConnectionFileSystem implements FileSystem {
@Override
public boolean mkdirs(String file) throws Exception {
try (var pc = shellControl.command(proc -> proc.getShellDialect()
.flatten(proc.getShellDialect()
.getMkdirsCommand(proc.getOsType().normalizeFileName(file))))
.getMkdirsCommand(proc.getOsType().normalizeFileName(file)))
.start()) {
return pc.discardAndCheckExit();
}
@@ -24,8 +24,7 @@ public class XPipeTempDirectory {
var dir = FileNames.join(base, "xpipe");
if (!proc.executeBooleanSimpleCommand(proc.getShellDialect().getFileExistsCommand(dir))) {
proc.executeSimpleCommand(
proc.getShellDialect().flatten(proc.getShellDialect().getMkdirsCommand(dir)),
proc.executeSimpleCommand(proc.getShellDialect().getMkdirsCommand(dir),
"Unable to access or create temporary directory " + dir);
if (proc.getOsType().equals(OsType.LINUX) || proc.getOsType().equals(OsType.MACOS)) {