@@ -144,6 +144,17 @@ def __init__(self, cli_ctx=None, command_cls=CLICommand, excluded_command_handle
144
144
self .argument_registry = ArgumentRegistry ()
145
145
self .extra_argument_registry = defaultdict (lambda : {})
146
146
147
+ def _populate_command_group_table_with_subgroups (self , name ):
148
+ if not name :
149
+ return
150
+
151
+ # ensure all subgroups have some entry in the command group table
152
+ name_components = name .split ()
153
+ for i , _ in enumerate (name_components ):
154
+ subgroup_name = ' ' .join (name_components [:i + 1 ])
155
+ if subgroup_name not in self .command_group_table :
156
+ self .command_group_table [subgroup_name ] = {}
157
+
147
158
def load_command_table (self , args ): # pylint: disable=unused-argument
148
159
""" Load commands into the command table
149
160
@@ -246,6 +257,7 @@ def __init__(self, command_loader, group_name, operations_tmpl, **kwargs):
246
257
Deprecated .ensure_new_style_deprecation (self .command_loader .cli_ctx , self .group_kwargs , 'command group' )
247
258
if kwargs ['deprecate_info' ]:
248
259
kwargs ['deprecate_info' ].target = group_name
260
+ command_loader ._populate_command_group_table_with_subgroups (group_name ) # pylint: disable=protected-access
249
261
self .command_loader .command_group_table [group_name ] = self
250
262
251
263
def __enter__ (self ):
@@ -273,6 +285,7 @@ def command(self, name, handler_name, **kwargs):
273
285
# don't inherit deprecation info from command group
274
286
command_kwargs ['deprecate_info' ] = kwargs .get ('deprecate_info' , None )
275
287
288
+ self .command_loader ._populate_command_group_table_with_subgroups (' ' .join (command_name .split ()[:- 1 ])) # pylint: disable=protected-access
276
289
self .command_loader .command_table [command_name ] = self .command_loader .create_command (
277
290
command_name ,
278
291
self .operations_tmpl .format (handler_name ),
0 commit comments