1111
1212logger = get_logger (__name__ )
1313
14+ STORED_DEPRECATION_KEY = ["expiration" , "target" , "redirect" , "hide" ]
15+
1416
1517class 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+
5586def 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
91122def 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+
148194def 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