
    L$                     ,   d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddlmZ ddl	m
Z
 dd	lmZ dd
lmZ ddlmZ ddlmZ dZdZ G d dej&                        Zd"dZd#dZd Zd"dZd#dZd Zd Zd Zd Zd Zd Zd$dZ d Z!d$dZ"d Z#d  Z$d! Z%y)%z6Shared resource flags for Transfer Appliance commands.    )absolute_import)division)unicode_literalsN)concepts)deps)regions)concept_parsers)presentation_specs)
properties)	resourcesz/transferappliance.projects.locations.appliancesz+transferappliance.projects.locations.ordersc                       e Zd ZdZdZdZdZy)ResourceVerbdeletedescribelistupdateN)__name__
__module____qualname__DELETEDESCRIBELISTUPDATE     Clib/googlecloudsdk/command_lib/transfer/appliances/resource_args.pyr   r   %   s    &(	$&r   r   c                 8    t        j                  | dddid      S )Nz-The appliance affiliated with the {resource}.	fieldMasknamer   	help_textcompletion_request_paramscompletion_id_fieldr    ResourceParameterAttributeConfigr   s    r   appliance_attribute_configr'   ,   s&    		2	2?!,f 5 	
" "r   c                 8    t        j                  | dddid      S )Nz)The order affiliated with the {resource}.r   r   r    r$   r&   s    r   order_attribute_configr)   4   s&    		2	2;!,f 5 	
" "r   c                  Z    t        j                  ddt        j                  d      g      S )Nregionz*The region affiliated with the {resource}.--region)r   r!   fallthroughs)r   r%   r   ArgFallthroughr   r   r   region_attribute_configr/   <   s,    		2	2<''
34
6 6r   c                     t        j                  t        | t        |       t	               t         j
                  d      S )Nr&   F)resource_nameappliancesIdlocationsId
projectsIddisable_auto_completers)r   ResourceSpecAPPLIANCES_COLLECTIONr'   r/    DEFAULT_PROJECT_ATTRIBUTE_CONFIGr1   s    r   get_appliance_resource_specr:   C   s5    			!-=A)+::#
% %r   c                     t        j                  t        | t        |       t	               t         j
                  d      S )Nr&   F)r1   ordersIdr3   r4   r5   )r   r6   ORDERS_COLLECTIONr)   r/   r8   r9   s    r   get_order_resource_specr>   M   s5    			!%=9)+::#
% %r   c                     | j                  dt        j                  t        j                  dj                  |j                               y)aU  Add region flag for appliances/orders.

  Normally we'd rely on the argument output by region_attribute_config() but
  we can set "choices" and convert the value to lower if we add it this way.

  Args:
    parser (arg_parse.Parser): The parser for the command.
    verb (ResourceVerb): The action taken on the resource, such as 'update'.
  r,   z7The location affiliated with the appliance order to {}.)choicestypehelpN)add_argumentr   CLOUD_REGIONSstrlowerformatvalueparserverbs     r   _add_region_flagrL   W   s?     	##99DKK
**	  r   c                     t         j                  j                  dt               dj	                  |j
                        ddidd      j                  |        t        | |       y)a  Add a resource argument for a transfer appliance.

  NOTE: Must be used only if it's the only resource arg in the command.

  Args:
    parser (arg_parse.Parser): The parser for the command.
    verb (ResourceVerb): The action taken on the resource, such as 'update'.
  	appliancezThe appliance to {}.r+    Tflag_name_overridesprefixesrequiredN)r	   ConceptParserForResourcer:   rG   rH   AddToParserrL   rI   s     r   add_appliance_resource_argrW   i   s[     ++!###DJJ/#R. ,  ![(64 r   c                     t         j                  j                  dt               dj	                  |j
                        ddidd      j                  |        t        | |       y)a  Add a resource argument for a transfer appliance order.

  NOTE: Must be used only if it's the only resource arg in the command.

  Args:
    parser (arg_parse.Parser): The parser for the command.
    verb (ResourceVerb): The action taken on the resource, such as 'update'.
  orderzThe order to {}.r+   rO   TrP   N)r	   rT   rU   r>   rG   rH   rV   rL   rI   s     r   add_order_resource_argrZ   |   s[     ++

+#R. ,  ![(64 r   c                 z    t         j                  j                  dt               ddd      j	                  |        y)zAdd a resource argument for cloning a transfer appliance.

  NOTE: Must be used only if it's the only resource arg in the command.

  Args:
    parser (arg_parse.Parser): The parser for the command.
  z--clonezThe order to clone.TF)rR   rS   N)r	   rT   rU   r>   rV   )rJ   s    r   add_clone_resource_argr\      s;     ++ , 
 "k&)r   c                     t         j                  j                  | j                  dt        j
                  j                  j                  j                         it              j                         S Nr4   )params
collection)r   REGISTRYParser   r   VALUEScoreprojectGetr7   SelfLinkrN   s    r   _get_appliance_uriri      sV    				!	!nnJ--22::>>@A& 
" 
( )1
3r   c                     t         j                  j                  | j                  dt        j
                  j                  j                  j                         it              j                         S r^   )r   ra   rb   r   r   rc   rd   re   rf   r=   rg   rY   s    r   _get_order_urirl      sV    				!	!jjJ--22::>>@A" 
" 
$ %-HJ/r   c           	         t         j                  }d}d}|rY|j                  d|j                        }|j                  dd|j                        }| j                  j                  t               nX|j                  d|j                        }|j                  dd|j                        }| j                  j                  t               t        j                  dt        d      |ddidd	
      t        j                  dt        d      |ddidd
      g}t        j                  |      j                  |        t        | |       y)a  Add both order and appliance resource arguments for list commands.

  Args:
    parser (arg_parse.Parser): The parser for the command.
    listing_orders (bool): Toggles the help text phrasing to match either orders
      or appliances being the resource being listed.
  zThe {} to {}.z$The {} associated with the {} to {}.orders
appliancesz--appliancesr+   rO   TF)rQ   pluralrR   z--ordersN)r   r   rG   rH   display_info
AddUriFuncrl   ri   r
   ResourcePresentationSpecr:   r>   r	   rT   rV   rL   )rJ   listing_ordersrK   primary_helpsecondary_helporders_helpappliances_help	arg_specss           r   add_list_resource_argsrz      s#    
		$ ,9.%%h

;K$++L(DJJOO
"">2")),

CO '',

KK
""#56 11

%l
3
'n 11

!(
+
'n)" 	*66v>64 r   c                     |sy|D cg c]"  }dj                  | |j                               $ }}dj                  |      }dj                  |      S c c}w )NrO   z{}:{}z OR z({}))rG   RelativeNamejoin)
filter_keyresource_refsreffilter_listresource_lists        r   !_get_filter_clause_from_resourcesr      s\    	@M@MgnnZ!1!1!34   ++k*-	}	%%	s   'Ac                    | j                   r| j                   gng }| j                  d      rG| j                  j                  j	                         }|r!|rdnd}|j                  t        ||             | j                  d      rG| j                  j                  j	                         }|r!|rdnd}|j                  t        ||             dj                  |      S )a5  Parses list resource args as a filter string.

  Args:
    args (parser_extensions.Namespace): the parsed arguments for the command.
    listing_orders (bool): Toggles the appropriate keys for order and appliance
      depending on which resource is primarily being listed.

  Returns:
    A filter string.
  rn   r   rY   ro   z AND )	filterIsSpecifiedCONCEPTSrn   rb   appendr   ro   r}   )argsrt   r   
order_refsr~   appliance_refss         r   )parse_list_resource_args_as_filter_stringr      s     "&"+	h%%++-J+6j:
j" #	l#]]--335N#1<vj:
n& '	k	""r   c                     t         j                  j                  j                  j	                         }dj                  || xs d      S )zHReturns a presentation string for list and create calls, given a region.zprojects/{}/locations/{}-)r   rc   rd   re   rf   rG   )r+   re   s     r   get_parent_stringr      s9    ""**..0'	#	*	*7FMc	BBr   c           	          t         j                  j                  t         j                  j	                  t
        || t        j                  j                  j                  j                                     S )z9Returns an appliance name to locations and appliances ID.)r2   r3   r4   )r   Resourcer|   ra   Creater7   r   rc   rd   re   rf   )locations_idappliances_ids     r   get_appliance_namer     s[    				(	(
$"&&++33779	   ;
< <r   c           	          t         j                  j                  t         j                  j	                  t
        || t        j                  j                  j                  j                                     S )z5Returns an appliance name to locations and orders ID.)r<   r3   r4   )r   r   r|   ra   r   r=   r   rc   rd   re   rf   )r   	orders_ids     r   get_order_namer     s[    				(	(
"&&++33779	   ;
< <r   rh   rk   )T)&__doc__
__future__r   r   r   enum googlecloudsdk.calliope.conceptsr   r   .googlecloudsdk.command_lib.transfer.appliancesr   (googlecloudsdk.command_lib.util.conceptsr	   r
   googlecloudsdk.corer   r   r7   r=   Enumr   r'   r)   r/   r:   r>   rL   rW   rZ   r\   ri   rl   rz   r   r   r   r   r   r   r   r   <module>r      s     = &  '  5 1 B D G * ) J A 499 ""6%%$!&!&* 3/&!R&#6C<<r   