Skip to content

Commit

Permalink
[fix][cli] Pulsar shell: fix using directory '?' in the docker image (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoloboschi authored Aug 22, 2022
1 parent e8ee996 commit 21730e9
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public class PulsarShell {
private static final String EXIT_MESSAGE = "Goodbye!";
private static final String PROPERTY_PULSAR_SHELL_DIR = "shellHistoryDirectory";
private static final String PROPERTY_PERSIST_HISTORY_ENABLED = "shellHistoryPersistEnabled";
private static final String PROPERTY_PERSIST_HISTORY_PATH = "shellHistoryPersistPath";
private static final String CHECKMARK = new String(Character.toChars(0x2714));
private static final String XMARK = new String(Character.toChars(0x2716));
private static final AttributedStyle LOG_STYLE = AttributedStyle.DEFAULT
Expand All @@ -87,6 +86,8 @@ public class PulsarShell {
}
};

private static final String DEFAULT_PULSAR_SHELL_ROOT_DIRECTORY = computeDefaultPulsarShellRootDirectory();

interface Substitutor {
String replace(String str, Map<String, String> vars);
}
Expand Down Expand Up @@ -185,12 +186,25 @@ public PulsarShell(String args[], Properties props) throws IOException {
private static File computePulsarShellFile() {
String dir = System.getProperty(PROPERTY_PULSAR_SHELL_DIR, null);
if (dir == null) {
return Paths.get(System.getProperty("user.home"), ".pulsar-shell").toFile();
return Paths.get(DEFAULT_PULSAR_SHELL_ROOT_DIRECTORY, ".pulsar-shell").toFile();
} else {
return new File(dir);
}
}

/**
* Compute the default Pulsar shell root directory.
* If system property "user.home" returns invalid value, the default value will be the current directory.
* @return
*/
private static String computeDefaultPulsarShellRootDirectory() {
final String userHome = System.getProperty("user.home");
if (!StringUtils.isBlank(userHome) && !"?".equals(userHome)) {
return userHome;
}
return System.getProperty("user.dir");
}

public static void main(String[] args) throws Exception {
new PulsarShell(args).run();
}
Expand Down

0 comments on commit 21730e9

Please sign in to comment.