Re: [PR] [improve][cli]Support for pulsar-shell persistent modes [pulsar]
sandeep-mst commented on code in PR #22522: URL: https://github.com/apache/pulsar/pull/22522#discussion_r1570513172 ## pulsar-client-tools/src/main/java/org/apache/pulsar/shell/PulsarShell.java: ## @@ -414,18 +441,34 @@ public List readCommand() { return; } execState = ExecState.RUNNING; -final String line = words.stream().collect(Collectors.joining(" ")); +String line = words.stream().collect(Collectors.joining(" ")); if (StringUtils.isBlank(line)) { continue; } if (isQuitCommand(line)) { +if (shellMode != ShellMode.DEFAULT) { +output(String.format("Exiting from %s shell mode", shellMode.command), terminal); +prompt = createPrompt(promptMessage); +shellMode = ShellMode.DEFAULT; +continue; +} exit(0); return; } +if (shellMode != ShellMode.DEFAULT) { +words.add(0, shellMode.command); +line = shellMode.command + " " + line; +} if (isHelp(line)) { shellCommander.usage(System.out); continue; } +ShellMode newShellMode = ShellMode.valueOfCommand(line.toLowerCase(Locale.ROOT)); +if (newShellMode != null) { Review Comment: Yes, I updated it. Now switching will only be possible at the top level. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@pulsar.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] [improve][cli]Support for pulsar-shell persistent modes [pulsar]
lhotari commented on code in PR #22522: URL: https://github.com/apache/pulsar/pull/22522#discussion_r1570436161 ## pulsar-client-tools/src/main/java/org/apache/pulsar/shell/PulsarShell.java: ## @@ -414,18 +441,34 @@ public List readCommand() { return; } execState = ExecState.RUNNING; -final String line = words.stream().collect(Collectors.joining(" ")); +String line = words.stream().collect(Collectors.joining(" ")); if (StringUtils.isBlank(line)) { continue; } if (isQuitCommand(line)) { +if (shellMode != ShellMode.DEFAULT) { +output(String.format("Exiting from %s shell mode", shellMode.command), terminal); +prompt = createPrompt(promptMessage); +shellMode = ShellMode.DEFAULT; +continue; +} exit(0); return; } +if (shellMode != ShellMode.DEFAULT) { +words.add(0, shellMode.command); +line = shellMode.command + " " + line; +} if (isHelp(line)) { shellCommander.usage(System.out); continue; } +ShellMode newShellMode = ShellMode.valueOfCommand(line.toLowerCase(Locale.ROOT)); +if (newShellMode != null) { Review Comment: checking for this makes only sense when `shellMode == ShellMode.DEFAULT`. Switching the shell mode should only be possible at the top level. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@pulsar.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] [improve][cli]Support for pulsar-shell persistent modes [pulsar]
sandeep-mst commented on code in PR #22522: URL: https://github.com/apache/pulsar/pull/22522#discussion_r1570388422 ## pulsar-client-tools/src/main/java/org/apache/pulsar/shell/PulsarShell.java: ## @@ -414,18 +441,36 @@ public List readCommand() { return; } execState = ExecState.RUNNING; -final String line = words.stream().collect(Collectors.joining(" ")); -if (StringUtils.isBlank(line)) { +final String inputLine = words.stream().collect(Collectors.joining(" ")); Review Comment: Updated it -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@pulsar.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] [improve][cli]Support for pulsar-shell persistent modes [pulsar]
sandeep-mst commented on code in PR #22522: URL: https://github.com/apache/pulsar/pull/22522#discussion_r1570389366 ## pulsar-client-tools/src/main/java/org/apache/pulsar/shell/PulsarShell.java: ## @@ -414,18 +441,36 @@ public List readCommand() { return; } execState = ExecState.RUNNING; -final String line = words.stream().collect(Collectors.joining(" ")); -if (StringUtils.isBlank(line)) { +final String inputLine = words.stream().collect(Collectors.joining(" ")); +if (StringUtils.isBlank(inputLine)) { continue; } -if (isQuitCommand(line)) { +if (isQuitCommand(inputLine)) { +if (shellMode != ShellMode.DEFAULT){ +output(String.format("Exiting from %s shell mode", shellMode.command), terminal); +promptMessage = promptMessage.substring(0, promptMessage.lastIndexOf(shellMode.command) - 1); Review Comment: yes, updated it. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@pulsar.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] [improve][cli]Support for pulsar-shell persistent modes [pulsar]
sandeep-mst commented on PR #22515: URL: https://github.com/apache/pulsar/pull/22515#issuecomment-2060792240 Closing in favour of https://github.com/apache/pulsar/pull/22522 I have resolved the review comments in that PR -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@pulsar.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] [improve][cli]Support for pulsar-shell persistent modes [pulsar]
lhotari commented on code in PR #22522: URL: https://github.com/apache/pulsar/pull/22522#discussion_r1568560031 ## pulsar-client-tools/src/main/java/org/apache/pulsar/shell/PulsarShell.java: ## @@ -414,18 +441,36 @@ public List readCommand() { return; } execState = ExecState.RUNNING; -final String line = words.stream().collect(Collectors.joining(" ")); -if (StringUtils.isBlank(line)) { +final String inputLine = words.stream().collect(Collectors.joining(" ")); Review Comment: perhaps `final` could be dropped so that the a single variable `line` could be used. ## pulsar-client-tools/src/main/java/org/apache/pulsar/shell/PulsarShell.java: ## @@ -414,18 +441,36 @@ public List readCommand() { return; } execState = ExecState.RUNNING; -final String line = words.stream().collect(Collectors.joining(" ")); -if (StringUtils.isBlank(line)) { +final String inputLine = words.stream().collect(Collectors.joining(" ")); +if (StringUtils.isBlank(inputLine)) { continue; } -if (isQuitCommand(line)) { +if (isQuitCommand(inputLine)) { +if (shellMode != ShellMode.DEFAULT){ +output(String.format("Exiting from %s shell mode", shellMode.command), terminal); +promptMessage = promptMessage.substring(0, promptMessage.lastIndexOf(shellMode.command) - 1); Review Comment: It might be better to keep the current shell mode out of the promptMessage and build the `prompt` from `promptMessage` and `shellMode.command` each time there are changes. ## pulsar-client-tools/src/main/java/org/apache/pulsar/shell/PulsarShell.java: ## @@ -414,18 +441,36 @@ public List readCommand() { return; } execState = ExecState.RUNNING; -final String line = words.stream().collect(Collectors.joining(" ")); -if (StringUtils.isBlank(line)) { +final String inputLine = words.stream().collect(Collectors.joining(" ")); +if (StringUtils.isBlank(inputLine)) { continue; } -if (isQuitCommand(line)) { +if (isQuitCommand(inputLine)) { +if (shellMode != ShellMode.DEFAULT){ +output(String.format("Exiting from %s shell mode", shellMode.command), terminal); +promptMessage = promptMessage.substring(0, promptMessage.lastIndexOf(shellMode.command) - 1); +prompt = createPrompt(promptMessage); +shellMode = ShellMode.DEFAULT; +continue; +} exit(0); return; } +if (shellMode != ShellMode.DEFAULT) { +words.add(0, shellMode.command); +} +final String line = words.stream().collect(Collectors.joining(" ")); if (isHelp(line)) { shellCommander.usage(System.out); continue; } +ShellMode newShellMode = ShellMode.valueOfCommand(line.toLowerCase(Locale.ROOT)); +if (newShellMode != null){ Review Comment: whitespace ```suggestion if (newShellMode != null) { ``` ## pulsar-client-tools/src/main/java/org/apache/pulsar/shell/PulsarShell.java: ## @@ -414,18 +441,36 @@ public List readCommand() { return; } execState = ExecState.RUNNING; -final String line = words.stream().collect(Collectors.joining(" ")); -if (StringUtils.isBlank(line)) { +final String inputLine = words.stream().collect(Collectors.joining(" ")); +if (StringUtils.isBlank(inputLine)) { continue; } -if (isQuitCommand(line)) { +if (isQuitCommand(inputLine)) { +if (shellMode != ShellMode.DEFAULT){ +output(String.format("Exiting from %s shell mode", shellMode.command), terminal); +promptMessage = promptMessage.substring(0, promptMessage.lastIndexOf(shellMode.command) - 1); +prompt = createPrompt(promptMessage); +shellMode = ShellMode.DEFAULT; +continue; +} exit(0); return; } +if (shellMode != ShellMode.DEFAULT) { +words.add(0, shellMode.command); +} +final String line = words.stream().collect(Collectors.joining(" ")); if (isHelp(line)) { shellCommander.usage(System.out); continue; } +ShellMode newShellMode =
Re: [PR] [improve][cli]Support for pulsar-shell persistent modes [pulsar]
sandeep-mst closed pull request #22515: [improve][cli]Support for pulsar-shell persistent modes URL: https://github.com/apache/pulsar/pull/22515 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@pulsar.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] [improve][cli]Support for pulsar-shell persistent modes [pulsar]
lhotari commented on code in PR #22515: URL: https://github.com/apache/pulsar/pull/22515#discussion_r1566816835 ## pulsar-client-tools/src/main/java/org/apache/pulsar/shell/PulsarShell.java: ## @@ -567,6 +602,14 @@ private static boolean isQuitCommand(String line) { return line.equalsIgnoreCase("quit") || line.equalsIgnoreCase("exit"); } +private static boolean isExitModeCommand(String line) { +return line.equalsIgnoreCase("exitmode"); +} + +private static boolean isChangeModeCommand(String line) { +return line.equalsIgnoreCase("admin") || line.equalsIgnoreCase("client") || line.equalsIgnoreCase("config"); Review Comment: for example https://www.baeldung.com/java-enum-values contains some advice how this could be handled. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@pulsar.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] [improve][cli]Support for pulsar-shell persistent modes [pulsar]
lhotari commented on PR #22515: URL: https://github.com/apache/pulsar/pull/22515#issuecomment-2058366744 @sandeep-mst Thanks for the contribution. Please target the `master` branch since we currently follow that type of process where PRs target the master branch when it's applicable. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@pulsar.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] [improve][cli]Support for pulsar-shell persistent modes [pulsar]
lhotari commented on code in PR #22515: URL: https://github.com/apache/pulsar/pull/22515#discussion_r1566813924 ## pulsar-client-tools/src/main/java/org/apache/pulsar/shell/PulsarShell.java: ## @@ -567,6 +602,14 @@ private static boolean isQuitCommand(String line) { return line.equalsIgnoreCase("quit") || line.equalsIgnoreCase("exit"); } +private static boolean isExitModeCommand(String line) { +return line.equalsIgnoreCase("exitmode"); +} + +private static boolean isChangeModeCommand(String line) { +return line.equalsIgnoreCase("admin") || line.equalsIgnoreCase("client") || line.equalsIgnoreCase("config"); Review Comment: seems like duplication. I'd assume that the ShellMode enum would have a status lookup method instead. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@pulsar.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] [improve][cli]Support for pulsar-shell persistent modes [pulsar]
lhotari commented on code in PR #22515: URL: https://github.com/apache/pulsar/pull/22515#discussion_r1566809132 ## pulsar-client-tools/src/main/java/org/apache/pulsar/shell/PulsarShell.java: ## @@ -567,6 +602,14 @@ private static boolean isQuitCommand(String line) { return line.equalsIgnoreCase("quit") || line.equalsIgnoreCase("exit"); } +private static boolean isExitModeCommand(String line) { +return line.equalsIgnoreCase("exitmode"); +} Review Comment: there shouldn't be a separate `exitmode` command. Simple `exit` or pressing CTRL-D should do that. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@pulsar.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org