Skip to content

Commit 7cbee25

Browse files
authored
Fix deprecation action. (#86)
1 parent 43e1875 commit 7cbee25

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

knack/arguments.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,9 @@ def argument(self, argument_dest, arg_type=None, **kwargs):
235235
:param kwargs: Possible values: `options_list`, `validator`, `completer`, `nargs`, `action`, `const`, `default`,
236236
`type`, `choices`, `required`, `help`, `metavar`. See /docs/arguments.md.
237237
"""
238-
kwargs['action'] = self._handle_deprecations(argument_dest, **kwargs)
238+
deprecate_action = self._handle_deprecations(argument_dest, **kwargs)
239+
if deprecate_action:
240+
kwargs['action'] = deprecate_action
239241
self.command_loader.argument_registry.register_cli_argument(self.command_scope,
240242
argument_dest,
241243
arg_type,
@@ -259,7 +261,9 @@ def extra(self, argument_dest, **kwargs):
259261
:param kwargs: Possible values: `options_list`, `validator`, `completer`, `nargs`, `action`, `const`, `default`,
260262
`type`, `choices`, `required`, `help`, `metavar`. See /docs/arguments.md.
261263
"""
262-
kwargs['action'] = self._handle_deprecations(argument_dest, **kwargs)
264+
deprecate_action = self._handle_deprecations(argument_dest, **kwargs)
265+
if deprecate_action:
266+
kwargs['action'] = deprecate_action
263267
self.command_loader.extra_argument_registry[self.command_scope][argument_dest] = CLICommandArgument(
264268
argument_dest, **kwargs)
265269

knack/commands.py

+13
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,17 @@ def __init__(self, cli_ctx=None, command_cls=CLICommand, excluded_command_handle
144144
self.argument_registry = ArgumentRegistry()
145145
self.extra_argument_registry = defaultdict(lambda: {})
146146

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+
147158
def load_command_table(self, args): # pylint: disable=unused-argument
148159
""" Load commands into the command table
149160
@@ -246,6 +257,7 @@ def __init__(self, command_loader, group_name, operations_tmpl, **kwargs):
246257
Deprecated.ensure_new_style_deprecation(self.command_loader.cli_ctx, self.group_kwargs, 'command group')
247258
if kwargs['deprecate_info']:
248259
kwargs['deprecate_info'].target = group_name
260+
command_loader._populate_command_group_table_with_subgroups(group_name) # pylint: disable=protected-access
249261
self.command_loader.command_group_table[group_name] = self
250262

251263
def __enter__(self):
@@ -273,6 +285,7 @@ def command(self, name, handler_name, **kwargs):
273285
# don't inherit deprecation info from command group
274286
command_kwargs['deprecate_info'] = kwargs.get('deprecate_info', None)
275287

288+
self.command_loader._populate_command_group_table_with_subgroups(' '.join(command_name.split()[:-1])) # pylint: disable=protected-access
276289
self.command_loader.command_table[command_name] = self.command_loader.create_command(
277290
command_name,
278291
self.operations_tmpl.format(handler_name),

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from codecs import open
1010
from setuptools import setup, find_packages
1111

12-
VERSION = '0.4.0'
12+
VERSION = '0.4.1'
1313

1414
DEPENDENCIES = [
1515
'argcomplete',

0 commit comments

Comments
 (0)