Skip to content

Commit 1a8594b

Browse files
almost done
1 parent 5f07222 commit 1a8594b

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

linodecli/help_pages.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -298,30 +298,34 @@ def _help_group_arguments(
298298
"""
299299
Returns help page groupings for a list of POST/PUT arguments.
300300
"""
301+
args = [arg for arg in args if not arg.read_only]
301302
args_sorted = sorted(args, key=lambda a: a.path)
302-
arg_parents = set(arg.parent for arg in args_sorted)
303303

304-
groups_tmp = defaultdict(list)
304+
paths = {tuple(arg.path.split(".")) for arg in args_sorted}
305+
path_to_args = defaultdict(list)
305306

306-
# Initial grouping by root parent
307307
for arg in args_sorted:
308-
if arg.read_only:
309-
continue
308+
arg_path = tuple(arg.path.split("."))
310309

311-
group_key = arg.path.split(".")[-1]
312-
if arg.parent:
313-
group_key = arg.parent
310+
if not arg.is_parent:
311+
# Parent arguments are grouped in with their children
312+
arg_path = arg_path[:-1]
314313

315-
if arg.path in arg_parents:
316-
group_key = arg.path
314+
print(arg.path, arg.is_parent, arg_path)
315+
# Find first common parent
316+
while len(arg_path) > 1 and arg_path not in paths:
317+
arg_path = arg_path[:-1]
317318

318-
groups_tmp[group_key].append(arg)
319+
print(arg.path, arg.is_parent, arg_path)
320+
path_to_args[arg_path].append(arg)
319321

320322
group_required = []
321323
groups = []
322324
ungrouped = []
323325

324-
for group in groups_tmp.values():
326+
for k, group in sorted(
327+
path_to_args.items(), key=lambda a: (a[0], len(a[1]))
328+
):
325329
# If the group has more than one element,
326330
# leave it as is in the result
327331
if len(group) > 1:

0 commit comments

Comments
 (0)