Skip to content

Commit fb8116a

Browse files
authored
add param deprecate expire info (#436)
* add param deprecate expir info
1 parent e370b9a commit fb8116a

2 files changed

Lines changed: 59 additions & 4 deletions

File tree

azdev/operations/command_change/__init__.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
# license information.
55
# -----------------------------------------------------------------------------
66

7-
# pylint: disable=no-else-return
7+
# pylint: disable=no-else-return, too-many-nested-blocks
88

99
import time
1010

1111
from knack.log import get_logger
1212
import azure_cli_diff_tool
1313
from azdev.utilities import display, require_azure_cli, heading, get_path_table, filter_by_git_diff
14-
from .custom import DiffExportFormat, get_commands_meta
14+
from .custom import DiffExportFormat, get_commands_meta, STORED_DEPRECATION_KEY
1515
from .util import export_commands_meta
1616
from ..statistics import _create_invoker_and_load_cmds, _get_command_source, \
1717
_command_codegen_info # pylint: disable=protected-access
@@ -92,6 +92,14 @@ def export_command_meta(modules=None, git_source=None, git_target=None, git_repo
9292
"supports_no_wait": command.supports_no_wait,
9393
"is_preview": command.command_kwargs.get("is_preview", False)
9494
}
95+
96+
if hasattr(command, "deprecate_info"):
97+
for info_key in STORED_DEPRECATION_KEY:
98+
if hasattr(command.deprecate_info, info_key) and getattr(command.deprecate_info, info_key):
99+
if command_info.get("deprecate_info", None) is None:
100+
command_info["deprecate_info"] = {}
101+
command_info["deprecate_info"][info_key] = getattr(command.deprecate_info, info_key)
102+
95103
module_loader = command_loader.cmd_to_loader_map[command_name]
96104
for loader in module_loader:
97105
loader.skip_applicability = True

azdev/operations/command_change/custom.py

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
logger = get_logger(__name__)
1313

14+
STORED_DEPRECATION_KEY = ["expiration", "target", "redirect", "hide"]
15+
1416

1517
class DiffExportFormat(Enum):
1618
DICT = "dict"
@@ -52,6 +54,35 @@ def process_arg_options(argument_settings, para):
5254
para["options"] = sorted(option_list)
5355

5456

57+
def process_arg_options_deprecation(argument_settings, para):
58+
if not argument_settings.get("options_list", None):
59+
return
60+
raw_options_list = argument_settings["options_list"]
61+
option_deprecation_list = []
62+
for opt in raw_options_list:
63+
opt_type = opt.__class__.__name__
64+
if opt_type != "Deprecated":
65+
continue
66+
opt_deprecation = {}
67+
for info_key in STORED_DEPRECATION_KEY:
68+
if hasattr(opt, info_key) and getattr(opt, info_key):
69+
opt_deprecation[info_key] = getattr(opt, info_key)
70+
option_deprecation_list.append(opt_deprecation)
71+
if len(option_deprecation_list) != 0:
72+
para["options_deprecate_info"] = option_deprecation_list
73+
74+
75+
def process_arg_deprecation(argument_settings, para):
76+
if argument_settings.get("deprecate_info", None) is None:
77+
return
78+
for info_key in STORED_DEPRECATION_KEY:
79+
if hasattr(argument_settings["deprecate_info"], info_key) and \
80+
getattr(argument_settings["deprecate_info"], info_key):
81+
if para.get("deprecate_info", None) is None:
82+
para["deprecate_info"] = {}
83+
para["deprecate_info"][info_key] = getattr(argument_settings["deprecate_info"], info_key)
84+
85+
5586
def process_arg_type(argument_settings, para):
5687
if not argument_settings.get("type", None):
5788
return
@@ -89,13 +120,13 @@ def normalize_para_type(type_opts, value):
89120

90121

91122
def gen_command_meta(command_info, with_help=False, with_example=False):
92-
stored_property_when_exist = ["confirmation", "supports_no_wait", "is_preview"]
123+
stored_property_when_exist = ["confirmation", "supports_no_wait", "is_preview", "deprecate_info"]
93124
command_meta = {
94125
"name": command_info["name"],
95126
"is_aaz": command_info["is_aaz"],
96127
}
97128
for prop in stored_property_when_exist:
98-
if command_info[prop]:
129+
if command_info.get(prop, None):
99130
command_meta[prop] = command_info[prop]
100131
if with_example:
101132
try:
@@ -120,7 +151,9 @@ def gen_command_meta(command_info, with_help=False, with_example=False):
120151
para = {
121152
"name": settings["dest"],
122153
}
154+
process_arg_deprecation(settings, para)
123155
process_arg_options(settings, para)
156+
process_arg_options_deprecation(settings, para)
124157
process_arg_type(settings, para)
125158
if settings.get("required", False):
126159
para["required"] = True
@@ -145,6 +178,19 @@ def gen_command_meta(command_info, with_help=False, with_example=False):
145178
return command_meta
146179

147180

181+
def process_command_group_deprecation(command_group_obj, command_group_info):
182+
if not hasattr(command_group_obj, "group_kwargs"):
183+
return
184+
group_kwargs = getattr(command_group_obj, "group_kwargs")
185+
if group_kwargs.get("deprecate_info", None) is None:
186+
return
187+
for info_key in STORED_DEPRECATION_KEY:
188+
if hasattr(group_kwargs["deprecate_info"], info_key) and getattr(group_kwargs["deprecate_info"], info_key):
189+
if command_group_info.get("deprecate_info", None) is None:
190+
command_group_info["deprecate_info"] = {}
191+
command_group_info["deprecate_info"][info_key] = getattr(group_kwargs["deprecate_info"], info_key)
192+
193+
148194
def get_commands_meta(command_group_table, commands_info, with_help, with_example):
149195
commands_meta = {}
150196

@@ -172,6 +218,7 @@ def get_commands_meta(command_group_table, commands_info, with_help, with_exampl
172218
"commands": {},
173219
"sub_groups": {}
174220
}
221+
process_command_group_deprecation(group_info, command_group_info["sub_groups"][group_name])
175222
if with_help:
176223
try:
177224
command_group_info["sub_groups"][group_name]["desc"] = group_info.help["short-summary"]

0 commit comments

Comments
 (0)