Skip to content

Commit

Permalink
Merge branch 'model-help-exit' into 'main'
Browse files Browse the repository at this point in the history
Adding exception handling to allow users to exit modelHelp with Control-D

See merge request weblogic-cloud/weblogic-deploy-tooling!1753
  • Loading branch information
robertpatrick committed Nov 23, 2024
2 parents 5bea6be + 14b92fb commit 0ecf0ef
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def interactive_help_main_loop(self):
self._output_buffer.add_output()
self._output_buffer.print_output()

command_str = _interactive_help_prompt(history[-1], reader)
command_str = self._interactive_help_prompt(history[-1], reader)

self._logger.exiting(class_name=_class_name, method_name=_method_name)

Expand Down Expand Up @@ -286,25 +286,32 @@ def _add_message(self, key, *args, **kwargs):
self._output_buffer.add_output('%s%s%s' % (prefix, message, suffix))


def _interactive_help_prompt(model_path, reader):
"""
Gets the next command from stdin or using JLine.
:param model_path: a current model path
:param reader: JLine reader, or None if JLine not supported
:return: returns when user types 'exit'
"""
prompt = '[%s] --> ' % model_path
def _interactive_help_prompt(self, model_path, reader):
"""
Gets the next command from stdin or using JLine.
:param model_path: a current model path
:param reader: JLine reader, or None if JLine not supported
:return: returns when user types 'exit'
"""
prompt = '[%s] --> ' % model_path

if reader:
command_str = reader.readLine(prompt)
else:
# prompt using sys.stdout.write to avoid newline
sys.stdout.write(prompt)
sys.stdout.flush()
command_str = raw_input('') # get command from stdin
if reader:
# reader is None if JLine is not loaded
from org.jline.reader import EndOfFileException

try:
command_str = reader.readLine(prompt)
except EndOfFileException,ex:
self._logger.fine('WLSDPLY-10141', error=ex)
command_str = 'exit'
else:
# prompt using sys.stdout.write to avoid newline
sys.stdout.write(prompt)
sys.stdout.flush()
command_str = raw_input('') # get command from stdin

command_str = ' '.join(command_str.split()) # remove extra white-space
return command_str
command_str = ' '.join(command_str.split()) # remove extra white-space
return command_str


def _canonical_path_from_model_path(model_path):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1704,6 +1704,7 @@ WLSDPLY-10136=Examples
WLSDPLY-10137=Model section {0} has no element {1} beneath it. Valid folders are: {2}. Valid attributes are {3}.
WLSDPLY-10138=Failed to describe location {0}: {1}
WLSDPLY-10140=Show details for the specified attribute location
WLSDPLY-10141=Gracefully exiting the Model Help tool due to a JLine EndOfFileException, which is usually triggered by the user pressing Control-D to exit the shell.

###############################################################################
# create messages (12000 - 14999) #
Expand Down

0 comments on commit 0ecf0ef

Please sign in to comment.