77
88# pylint: disable=too-many-lines
99# pylint: disable=too-many-statements
10+ # pylint: disable=protected-access
1011
1112from knack .log import get_logger
12- from azure .cli .core .aaz import has_value , AAZAnyType , AAZListArg , AAZStrArg
13- from azure .cli .core .aaz ._arg_action import AAZArgActionOperations , AAZPromptInputOperation , _ELEMENT_APPEND_KEY
13+ from azure .cli .core .aaz import (
14+ has_value ,
15+ AAZAnyType ,
16+ AAZListArg ,
17+ AAZStrArg ,
18+ AAZObjectType ,
19+ AAZStrType ,
20+ AAZListType ,
21+ )
22+ from azure .cli .core .aaz ._arg_action import (
23+ AAZArgActionOperations ,
24+ AAZPromptInputOperation ,
25+ _ELEMENT_APPEND_KEY ,
26+ )
1427from azure .cli .core .azclierror import InvalidArgumentValueError
15- from azext_change_state .aaz .latest .change_safety .change_state import Create as _ChangeStateCreate , Update as _ChangeStateUpdate , Show as _ChangeStateShow , Delete as _ChangeStateDelete
16- from azure .cli .core .aaz import AAZObjectType , AAZStrType , AAZListType
28+ from azext_change_state .aaz .latest .change_safety .change_state import (
29+ Create as _ChangeStateCreate ,
30+ Update as _ChangeStateUpdate ,
31+ Show as _ChangeStateShow ,
32+ Delete as _ChangeStateDelete ,
33+ )
1734
1835
1936logger = get_logger (__name__ )
2037
2138
39+ def _build_any_type ():
40+ """Utility to satisfy schema_builder callsites while keeping lint happy."""
41+ return AAZAnyType ()
42+
43+
2244def _inject_change_definition_into_content (content , ctx ):
2345 """Attach the computed changeDefinition payload to the serialized request content."""
2446 change_definition_value = getattr (ctx .vars , "change_definition" , None )
@@ -112,6 +134,7 @@ def process(item):
112134 else :
113135 process (data )
114136
137+
115138def _custom_show_schema_builder ():
116139 # Import the generated Show class
117140 from azext_change_state .aaz .latest .change_safety .change_state ._show import Show as GeneratedShow
@@ -171,13 +194,22 @@ def pre_operations(self):
171194 # Build and set the changeDefinition with targets
172195 change_definition = self ._build_change_definition ()
173196 logger .debug ("Final changeDefinition for create: %s" , change_definition )
174- self .ctx .set_var ('change_definition' , change_definition , schema_builder = lambda : AAZAnyType ())
197+ self .ctx .set_var (
198+ 'change_definition' ,
199+ change_definition ,
200+ schema_builder = _build_any_type ,
201+ )
175202
176203 def _build_change_definition (self ):
177204 """Build the changeDefinition object with targets"""
178205 targets = self ._parse_targets (self ._raw_targets )
179206 self ._parsed_targets = targets
180- change_name = self .ctx .args .change_state_name .to_serialized_data () if has_value (self .ctx .args .change_state_name ) else "Change Definition"
207+ change_arg = self .ctx .args .change_state_name
208+ change_name = (
209+ change_arg .to_serialized_data ()
210+ if has_value (change_arg )
211+ else "Change Definition"
212+ )
181213
182214 return {
183215 'kind' : 'Targets' ,
@@ -250,13 +282,15 @@ def pre_instance_create(self):
250282 # The changeDefinition will be set in the content property of the HTTP operations
251283 pass
252284
253- class ChangeStatesCreateOrUpdateAtSubscriptionLevel (_ChangeStateCreate .ChangeStatesCreateOrUpdateAtSubscriptionLevel ):
285+ class ChangeStatesCreateOrUpdateAtSubscriptionLevel (
286+ _ChangeStateCreate .ChangeStatesCreateOrUpdateAtSubscriptionLevel ):
254287 @property
255288 def content (self ):
256289 content = super ().content
257290 return _inject_change_definition_into_content (content , self .ctx )
258291
259- class ChangeStatesCreateOrUpdate (_ChangeStateCreate .ChangeStatesCreateOrUpdate ):
292+ class ChangeStatesCreateOrUpdate (
293+ _ChangeStateCreate .ChangeStatesCreateOrUpdate ):
260294 @property
261295 def content (self ):
262296 content = super ().content
@@ -298,13 +332,22 @@ def pre_operations(self):
298332 if self ._raw_targets :
299333 change_definition = self ._build_change_definition ()
300334 logger .debug ("Final changeDefinition for update: %s" , change_definition )
301- self .ctx .set_var ('change_definition' , change_definition , schema_builder = lambda : AAZAnyType ())
335+ self .ctx .set_var (
336+ 'change_definition' ,
337+ change_definition ,
338+ schema_builder = _build_any_type ,
339+ )
302340
303341 def _build_change_definition (self ):
304342 """Build the changeDefinition object with targets"""
305343 targets = self ._parse_targets (self ._raw_targets )
306344 self ._parsed_targets = targets
307- change_name = self .ctx .args .change_state_name .to_serialized_data () if has_value (self .ctx .args .change_state_name ) else "Change Definition"
345+ change_arg = self .ctx .args .change_state_name
346+ change_name = (
347+ change_arg .to_serialized_data ()
348+ if has_value (change_arg )
349+ else "Change Definition"
350+ )
308351
309352 return {
310353 'kind' : 'Targets' ,
@@ -337,7 +380,11 @@ def _parse_targets(self, raw_targets):
337380 target_entry = {}
338381 for segment in segments :
339382 if '=' not in segment :
340- raise InvalidArgumentValueError (f"Each --targets entry must be in key=value format. Invalid: '{ segment } '" )
383+ error_message = (
384+ "Each --targets entry must be in key=value format. "
385+ f"Invalid: '{ segment } '"
386+ )
387+ raise InvalidArgumentValueError (error_message )
341388
342389 key , value = segment .split ('=' , 1 )
343390 key = key .strip ()
@@ -380,25 +427,29 @@ def _output(self, *args, **kwargs):
380427 _inject_targets_into_result (result , self ._parsed_targets )
381428 return result
382429
383- def pre_instance_update (self ):
430+ def pre_instance_update (self , instance ):
384431 """Set the changeDefinition in the request body before updating the instance"""
432+ del instance
385433 change_definition = getattr (self .ctx .vars , 'change_definition' , None )
386434 if change_definition is not None :
387435 # The changeDefinition will be set in the content property of the HTTP operations
388436 pass
389437
390- class ChangeStatesCreateOrUpdateAtSubscriptionLevel (_ChangeStateUpdate .ChangeStatesCreateOrUpdateAtSubscriptionLevel ):
438+ class ChangeStatesCreateOrUpdateAtSubscriptionLevel (
439+ _ChangeStateUpdate .ChangeStatesCreateOrUpdateAtSubscriptionLevel ):
391440 @property
392441 def content (self ):
393442 content = super ().content
394443 return _inject_change_definition_into_content (content , self .ctx )
395444
396- class ChangeStatesCreateOrUpdate (_ChangeStateUpdate .ChangeStatesCreateOrUpdate ):
445+ class ChangeStatesCreateOrUpdate (
446+ _ChangeStateUpdate .ChangeStatesCreateOrUpdate ):
397447 @property
398448 def content (self ):
399449 content = super ().content
400450 return _inject_change_definition_into_content (content , self .ctx )
401451
452+
402453class ChangeStateShow (_ChangeStateShow ):
403454 def _output (self , * args , ** kwargs ):
404455 result = super ()._output (* args , ** kwargs )
@@ -423,5 +474,6 @@ def on_200(self, session):
423474 schema_builder = _custom_show_schema_builder
424475 )
425476
477+
426478class ChangeStateDelete (_ChangeStateDelete ):
427479 pass
0 commit comments