You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by ni...@apache.org on 2022/09/16 10:08:20 UTC
[pulsar] branch branch-2.11 updated: [improve][cli] Pulsar shell: allow to create a new config (--file) with a relative path (#17675)
This is an automated email from the ASF dual-hosted git repository.
nicoloboschi pushed a commit to branch branch-2.11
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/branch-2.11 by this push:
new 4b99eeefd83 [improve][cli] Pulsar shell: allow to create a new config (--file) with a relative path (#17675)
4b99eeefd83 is described below
commit 4b99eeefd83aebcabdf16cfc6b4ef63190ee32eb
Author: Nicolò Boschi <bo...@gmail.com>
AuthorDate: Fri Sep 16 12:03:16 2022 +0200
[improve][cli] Pulsar shell: allow to create a new config (--file) with a relative path (#17675)
* [improve][cli] Pulsar shell: allow to create a new config (--file) with a relative path
* win
* checkstlye
(cherry picked from commit d7c09be15c3502e95bbd5862b210cc8d7f473c1e)
---
bin/pulsar-shell | 1 +
.../src/main/java/org/apache/pulsar/shell/ConfigShell.java | 11 ++++++++++-
.../java/org/apache/pulsar/shell/JCommanderCompleter.java | 3 +--
3 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/bin/pulsar-shell b/bin/pulsar-shell
index b0ad7cec84d..ca3533fb9ec 100755
--- a/bin/pulsar-shell
+++ b/bin/pulsar-shell
@@ -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"
exec $JAVA $OPTS $DEFAULT_CONFIG org.apache.pulsar.shell.PulsarShell "$@"
\ No newline at end of file
diff --git a/pulsar-client-tools/src/main/java/org/apache/pulsar/shell/ConfigShell.java b/pulsar-client-tools/src/main/java/org/apache/pulsar/shell/ConfigShell.java
index 48bc423336d..7aa87f07055 100644
--- a/pulsar-client-tools/src/main/java/org/apache/pulsar/shell/ConfigShell.java
+++ b/pulsar-client-tools/src/main/java/org/apache/pulsar/shell/ConfigShell.java
@@ -50,6 +50,15 @@ import org.apache.pulsar.shell.config.ConfigStore;
@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
@@ -305,7 +314,7 @@ public class ConfigShell implements ShellCommandsProvider {
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;
diff --git a/pulsar-client-tools/src/main/java/org/apache/pulsar/shell/JCommanderCompleter.java b/pulsar-client-tools/src/main/java/org/apache/pulsar/shell/JCommanderCompleter.java
index 6ef608173fd..4f75243ccd0 100644
--- a/pulsar-client-tools/src/main/java/org/apache/pulsar/shell/JCommanderCompleter.java
+++ b/pulsar-client-tools/src/main/java/org/apache/pulsar/shell/JCommanderCompleter.java
@@ -22,7 +22,6 @@ import static java.lang.annotation.ElementType.FIELD;
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;
@@ -172,7 +171,7 @@ public class JCommanderCompleter {
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