Skip to content

Commit 8be4701

Browse files
committed
Revised k8s model help to use hyphenated lists
1 parent 39b240b commit 8be4701

File tree

1 file changed

+34
-24
lines changed

1 file changed

+34
-24
lines changed

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

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ def _print_model_section_sample(self, section_name, control_option):
4646
_print_indent(path, 0)
4747

4848
if model_help_utils.show_attributes(control_option):
49-
self._print_attributes_sample(self._schema, 1)
49+
self._print_attributes_sample(self._schema, 1, False)
5050

5151
if model_help_utils.show_folders(control_option):
52-
self._print_subfolders_sample(self._schema, control_option, 1, path)
52+
self._print_subfolders_sample(self._schema, control_option, 1, path, False)
5353

5454
def _print_model_folder_sample(self, section_name, model_path_tokens, control_option):
5555
"""
@@ -69,6 +69,7 @@ def _print_model_folder_sample(self, section_name, model_path_tokens, control_op
6969
_print_indent(section_name + ":", indent)
7070
indent += 1
7171

72+
in_object_array = False
7273
model_path = section_name + ":"
7374
current_folder = self._schema
7475
for token in model_path_tokens[1:]:
@@ -83,31 +84,30 @@ def _print_model_folder_sample(self, section_name, model_path_tokens, control_op
8384

8485
current_folder = properties[token]
8586

86-
_print_indent(token + ":", indent)
87+
_print_indent(token + ":", indent, in_object_array)
8788
indent += 1
8889

89-
if wko_schema_helper.is_object_array(current_folder):
90-
name = token + '-1'
91-
_print_indent(name + ":", indent)
92-
indent += 1
93-
90+
# apply to the next folder in the path
91+
in_object_array = wko_schema_helper.is_object_array(current_folder)
9492
model_path = model_path + "/" + token
9593

9694
# list the attributes and folders, as specified
9795

9896
if model_help_utils.show_attributes(control_option):
9997
# Print the attributes associated with schema folder
100-
self._print_attributes_sample(current_folder, indent)
98+
in_object_array = self._print_attributes_sample(current_folder, indent, in_object_array)
10199

102100
if model_help_utils.show_folders(control_option):
103-
self._print_subfolders_sample(current_folder, control_option, indent, model_path)
101+
self._print_subfolders_sample(current_folder, control_option, indent, model_path, in_object_array)
104102

105-
def _print_subfolders_sample(self, schema_folder, control_option, indent_level, path):
103+
def _print_subfolders_sample(self, schema_folder, control_option, indent_level, path, in_object_array):
106104
"""
107105
Prints a model sample section for the folders in a model location.
108106
:param schema_folder: the schema folder being printed
109107
:param control_option: a command-line switch that controls what is output to STDOUT
110108
:param indent_level: the level to indent by, before printing output
109+
:param path: indicates path to request for child folder help
110+
:param in_object_array: if True, a hyphen is printed before the first attribute
111111
"""
112112
_method_name = '_print_subfolders_sample'
113113

@@ -135,27 +135,29 @@ def _print_subfolders_sample(self, schema_folder, control_option, indent_level,
135135
if control_option != ControlOptions.RECURSIVE:
136136
print("")
137137

138-
key_level = indent_level
139-
_print_indent(key + ":", key_level)
138+
_print_indent(key + ":", indent_level, in_object_array)
139+
in_object_array = False
140140

141-
child_level = key_level
142-
if key in multi_folders:
143-
name = key + "-1"
144-
child_level += 1
145-
_print_indent(name + ":", child_level)
141+
child_level = indent_level + 1
146142

143+
next_path = path + "/" + key
147144
if control_option == ControlOptions.RECURSIVE:
148145
# Call this method recursively
149-
self._print_subfolders_sample(folder_info, control_option, child_level + 1, path)
146+
child_in_object_array = key in multi_folders
147+
self._print_subfolders_sample(folder_info, control_option, child_level, path,
148+
child_in_object_array)
150149
else:
151-
next_path = path + "/" + key
152-
_print_indent("# see " + next_path, child_level + 1)
150+
_print_indent("# see " + next_path, child_level)
151+
152+
return in_object_array
153153

154-
def _print_attributes_sample(self, schema_folder, indent_level):
154+
def _print_attributes_sample(self, schema_folder, indent_level, in_object_array):
155155
"""
156156
Prints a model sample for the attributes in a model location
157157
:param schema_folder: the schema folder to be printed
158158
:param indent_level: the level of indentation for this folder
159+
:param in_object_array: if True, a hyphen is printed before the first attribute
160+
:return: value of in_object_array, or False if an attribute was printed with a hyphen
159161
"""
160162
_method_name = '_print_attributes_sample'
161163

@@ -192,10 +194,13 @@ def _print_attributes_sample(self, schema_folder, indent_level):
192194
format_string = '%-' + str(maxlen + 1) + 's # %s'
193195
for attr_name in attr_list:
194196
line = format_string % (attr_name + ":", attribute_map[attr_name])
195-
_print_indent(line, indent_level)
197+
_print_indent(line, indent_level, in_object_array)
198+
in_object_array = False
196199
else:
197200
_print_indent("# no attributes", indent_level)
198201

202+
return in_object_array
203+
199204

200205
def _get_properties(schema_folder):
201206
# in array elements, the properties are under "items"
@@ -221,15 +226,20 @@ def _get_folder_names(schema_properties):
221226
return folder_names
222227

223228

224-
def _print_indent(msg, level=1):
229+
def _print_indent(msg, level=1, first_in_list_object=False):
225230
"""
226231
Print a message at the specified indent level.
227232
:param msg: the message to be printed
228233
:param level: the indent level
234+
:param first_in_list_object: True if this is the first property of an object in a list
229235
"""
230236
result = ''
231237
i = 0
232238
while i < level:
233239
result += ' '
234240
i += 1
241+
242+
if first_in_list_object:
243+
result = result[:-2] + "- "
244+
235245
print '%s%s' % (result, msg)

0 commit comments

Comments
 (0)