Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[improve][cli] Pulsar shell: allow to create a new config (--file) with a relative path #17675

Merged
merged 3 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/pulsar-shell
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ BINDIR=$(dirname "$PRG")
export PULSAR_HOME=`cd -P $BINDIR/..;pwd`
. "$PULSAR_HOME/bin/pulsar-admin-common.sh"
OPTS="-Dorg.jline.terminal.jansi=false $OPTS"
OPTS="-Dpulsar.shell.working.dir=$(pwd) $OPTS"
DEFAULT_CONFIG="-Dpulsar.shell.config.default=$PULSAR_CLIENT_CONF"

#Change to PULSAR_HOME to support relative paths
Expand Down
1 change: 1 addition & 0 deletions bin/pulsar-shell.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ if ERRORLEVEL 1 (
)

set "OPTS=%OPTS% -Dorg.jline.terminal.jansi=false"
set "OPTS=%OPTS% -Dpulsar.shell.config.default=%cd%"
set "DEFAULT_CONFIG=-Dpulsar.shell.config.default="%PULSAR_CLIENT_CONF%""
cd "%PULSAR_HOME%"
"%JAVACMD%" %OPTS% %DEFAULT_CONFIG% org.apache.pulsar.shell.PulsarShell %*
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@
@Parameters(commandDescription = "Manage Pulsar shell configurations.")
public class ConfigShell implements ShellCommandsProvider {

private static final String LOCAL_FILES_BASE_DIR = System.getProperty("pulsar.shell.working.dir");

static File resolveLocalFile(String input) {
if (LOCAL_FILES_BASE_DIR != null) {
return new File(LOCAL_FILES_BASE_DIR, input);
}
return new File(input);
}


@Getter
@Parameters
Expand Down Expand Up @@ -305,7 +314,7 @@ public boolean run() {
value = inlineValue;
}
} else if (file != null) {
final File f = new File(file);
final File f = resolveLocalFile(file);
if (!f.exists()) {
print("File " + f.getAbsolutePath() + " not found.");
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.beust.jcommander.JCommander;
import com.beust.jcommander.ParameterDescription;
import com.beust.jcommander.WrappedParameter;
import java.io.File;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import java.lang.reflect.Field;
Expand Down Expand Up @@ -172,7 +171,7 @@ private static Completer getCustomCompleter(ParameterDescription param, ShellCon
if (parameterCompleter != null) {
final ParameterCompleter.Type completer = parameterCompleter.type();
if (completer == ParameterCompleter.Type.FILES) {
valueCompleter = new Completers.FilesCompleter(new File(System.getProperty("user.dir")));
valueCompleter = new Completers.FilesCompleter(ConfigShell.resolveLocalFile("."));
} else if (completer == ParameterCompleter.Type.CONFIGS) {
valueCompleter = new Completer() {
@Override
Expand Down