Skip to content

Commit 0ecf0ef

Browse files
committed
Merge branch 'model-help-exit' into 'main'
Adding exception handling to allow users to exit modelHelp with Control-D See merge request weblogic-cloud/weblogic-deploy-tooling!1753
2 parents 5bea6be + 14b92fb commit 0ecf0ef

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

core/src/main/python/wlsdeploy/tool/modelhelp/model_help_interactive_printer.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def interactive_help_main_loop(self):
6666
self._output_buffer.add_output()
6767
self._output_buffer.print_output()
6868

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

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

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

288288

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

298-
if reader:
299-
command_str = reader.readLine(prompt)
300-
else:
301-
# prompt using sys.stdout.write to avoid newline
302-
sys.stdout.write(prompt)
303-
sys.stdout.flush()
304-
command_str = raw_input('') # get command from stdin
298+
if reader:
299+
# reader is None if JLine is not loaded
300+
from org.jline.reader import EndOfFileException
301+
302+
try:
303+
command_str = reader.readLine(prompt)
304+
except EndOfFileException,ex:
305+
self._logger.fine('WLSDPLY-10141', error=ex)
306+
command_str = 'exit'
307+
else:
308+
# prompt using sys.stdout.write to avoid newline
309+
sys.stdout.write(prompt)
310+
sys.stdout.flush()
311+
command_str = raw_input('') # get command from stdin
305312

306-
command_str = ' '.join(command_str.split()) # remove extra white-space
307-
return command_str
313+
command_str = ' '.join(command_str.split()) # remove extra white-space
314+
return command_str
308315

309316

310317
def _canonical_path_from_model_path(model_path):

core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,6 +1704,7 @@ WLSDPLY-10136=Examples
17041704
WLSDPLY-10137=Model section {0} has no element {1} beneath it. Valid folders are: {2}. Valid attributes are {3}.
17051705
WLSDPLY-10138=Failed to describe location {0}: {1}
17061706
WLSDPLY-10140=Show details for the specified attribute location
1707+
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.
17071708

17081709
###############################################################################
17091710
# create messages (12000 - 14999) #

0 commit comments

Comments
 (0)