mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-04-24 16:40:58 -04:00
Rework elevation function
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package io.xpipe.core.process;
|
||||
|
||||
import io.xpipe.core.util.FailableConsumer;
|
||||
import io.xpipe.core.util.FailableFunction;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
@@ -64,11 +63,7 @@ public interface CommandControl extends ProcessControl {
|
||||
|
||||
long getExitCode();
|
||||
|
||||
default CommandControl elevated(String message) {
|
||||
return elevated(message, (v) -> true);
|
||||
}
|
||||
|
||||
CommandControl elevated(String message, FailableFunction<ShellControl, Boolean, Exception> elevationFunction);
|
||||
CommandControl elevated(ElevationFunction function);
|
||||
|
||||
void withStdoutOrThrow(FailableConsumer<InputStreamReader, Exception> c);
|
||||
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
package io.xpipe.core.process;
|
||||
|
||||
import lombok.Value;
|
||||
|
||||
@Value
|
||||
public class ElevationConfig {
|
||||
|
||||
boolean requiresPassword;
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package io.xpipe.core.process;
|
||||
|
||||
import io.xpipe.core.util.FailableFunction;
|
||||
|
||||
public interface ElevationFunction {
|
||||
|
||||
static ElevationFunction of(String prefix, FailableFunction<ShellControl, Boolean, Exception> f) {
|
||||
return new ElevationFunction() {
|
||||
@Override
|
||||
public String getPrefix() {
|
||||
return prefix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSpecified() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(ShellControl shellControl) throws Exception {
|
||||
return f.apply(shellControl);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
static ElevationFunction elevated(String prefix) {
|
||||
return new ElevationFunction() {
|
||||
@Override
|
||||
public String getPrefix() {
|
||||
return prefix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSpecified() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(ShellControl shellControl) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
static ElevationFunction none() {
|
||||
return new ElevationFunction() {
|
||||
@Override
|
||||
public String getPrefix() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSpecified() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(ShellControl shellControl) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
String getPrefix();
|
||||
|
||||
boolean isSpecified();
|
||||
|
||||
boolean apply(ShellControl shellControl) throws Exception;
|
||||
}
|
||||
@@ -171,7 +171,7 @@ public interface ShellControl extends ProcessControl {
|
||||
|
||||
OsType.Any getOsType();
|
||||
|
||||
ShellControl elevated(String message, FailableFunction<ShellControl, Boolean, Exception> elevationFunction);
|
||||
ShellControl elevated(ElevationFunction elevationFunction);
|
||||
|
||||
ShellControl withInitSnippet(ScriptSnippet snippet);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user