mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-08-23 17:56:29 +00:00
Rework on shells
This commit is contained in:
@@ -11,6 +11,8 @@ public interface OsType {
|
||||
Linux LINUX = new Linux();
|
||||
Mac MAC = new Mac();
|
||||
|
||||
String getScriptFileEnding();
|
||||
|
||||
String getName();
|
||||
|
||||
String getTempDirectory(ShellProcessControl pc) throws Exception;
|
||||
@@ -40,6 +42,11 @@ public interface OsType {
|
||||
|
||||
static class Windows implements OsType {
|
||||
|
||||
@Override
|
||||
public String getScriptFileEnding() {
|
||||
return "bat";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Windows";
|
||||
@@ -98,6 +105,11 @@ public interface OsType {
|
||||
return String.join("/", file.split("[\\\\/]+"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getScriptFileEnding() {
|
||||
return "sh";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Linux";
|
||||
@@ -168,6 +180,11 @@ public interface OsType {
|
||||
return String.join("/", file.split("[\\\\/]+"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getScriptFileEnding() {
|
||||
return "sh";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Mac";
|
||||
|
||||
@@ -11,6 +11,12 @@ import java.util.stream.Collectors;
|
||||
|
||||
public interface ShellProcessControl extends ProcessControl {
|
||||
|
||||
default String prepareOpen() throws Exception {
|
||||
return prepareOpen(null);
|
||||
}
|
||||
|
||||
String prepareOpen(String content) throws Exception;
|
||||
|
||||
default String executeSimpleCommand(String command) throws Exception {
|
||||
try (CommandProcessControl c = command(command).start()) {
|
||||
return c.readOrThrow();
|
||||
|
||||
@@ -10,6 +10,10 @@ import java.util.stream.Collectors;
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
|
||||
public interface ShellType {
|
||||
|
||||
String createInitFileContent(String command);
|
||||
|
||||
List<String> getOpenWithInitFileCommand(String file);
|
||||
|
||||
default String flatten(List<String> command) {
|
||||
return command.stream().map(s -> s.contains(" ") ? "\"" + s + "\"" : s).collect(Collectors.joining(" "));
|
||||
}
|
||||
@@ -65,5 +69,7 @@ public interface ShellType {
|
||||
|
||||
String getDisplayName();
|
||||
|
||||
String getExecutable();
|
||||
|
||||
boolean echoesInput();
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
package io.xpipe.core.store;
|
||||
|
||||
public class DataStoreFormatter {
|
||||
|
||||
public static String ellipsis(String input, int length) {
|
||||
if (input == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
var end = Math.min(input.length(), length);
|
||||
if (end < input.length()) {
|
||||
return input.substring(0, end) + "...";
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
public static String specialFormatHostName(String input) {
|
||||
if (input.contains(":")) {
|
||||
input = input.split(":")[0];
|
||||
}
|
||||
|
||||
if (input.endsWith(".rds.amazonaws.com")) {
|
||||
var split = input.split("\\.");
|
||||
var name = split[0];
|
||||
var region = split[2];
|
||||
return String.format("RDS %s @ %s", name, region);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,7 @@ public class CoreJacksonModule extends SimpleModule {
|
||||
new NamedType(WildcardType.class),
|
||||
new NamedType(ShellTypes.Cmd.class),
|
||||
new NamedType(ShellTypes.PowerShell.class),
|
||||
new NamedType(ShellTypes.Sh.class),
|
||||
new NamedType(ShellTypes.PosixBase.class),
|
||||
new NamedType(BaseQueryElement.class),
|
||||
new NamedType(ChoiceElement.class),
|
||||
new NamedType(BusyElement.class),
|
||||
|
||||
Reference in New Issue
Block a user