o @&a+@sddlZddlZddlZddlZddlmZddlmZddlm Z ddl m Z e e ZGdddeZGdd d eZGd d d eZGd d d e ZGdddeZGdddeZdS)N)raw_config_parsecompat_shell_quote) CLICommand) emit_top_level_args_parsed_eventc@s eZdZdS)InvalidAliasExceptionN)__name__ __module__ __qualname__r r ./usr/lib/python3/dist-packages/awscli/alias.pyrsrc@sNeZdZejejddddfddZddZd d Z d d Z d dZ dS) AliasLoader~z.awsclialiascCs||_d|_dS)zInterface for loading and interacting with alias file :param alias_filename: The name of the file to load aliases from. This file must be an INI file. N) _filename_aliases)selfalias_filenamer r r __init__!s zAliasLoader.__init__cCs"||_||jdidSNtoplevel) _load_aliasesr_cleanup_alias_valuesgetrr r r _build_aliases,s zAliasLoader._build_aliasescCs$tj|jrt|jddSdiiS)NF)parse_subsectionsr)ospathexistsrrrr r r r0s zAliasLoader._load_aliasescCs|D] }||||<qdSN)strip)raliasesrr r r r6sz!AliasLoader._cleanup_alias_valuescCs |jdur ||jdiSr)rrrrr r r get_aliases<s zAliasLoader.get_aliasesN) rr r rr expanduserjoinrrrrr$r r r r r s   r c@seZdZddZddZdS)AliasCommandInjectorcC||_||_dS)zInjects alias commands for a command table :type session: botocore.session.Session :param session: The botocore session :type alias_loader: awscli.alias.AliasLoader :param alias_loader: The alias loader to use N)_session _alias_loader)rsession alias_loaderr r r rCs zAliasCommandInjector.__init__cCsh|jD]*\}}|drt||}n|||j||g}||vr)|||t|}|||<qdS)N!)r*r$items startswithExternalAliasCommandr)appendServiceAliasCommand)r command_tableparser alias_name alias_value alias_cmdservice_alias_cmd_argsr r r inject_aliasesOs     z#AliasCommandInjector.inject_aliasesN)rr r rr9r r r r r'Bs r'c@s:eZdZdZddZddZeddZejddZd S) BaseAliasCommandTcCr()a%Base class for alias command :type alias_name: string :param alias_name: The name of the alias :type alias_value: string :param alias_value: The parsed value of the alias. This can be retrieved from `AliasLoader.get_aliases()[alias_name]` N) _alias_name _alias_value)rr5r6r r r rgs zBaseAliasCommand.__init__cCstd)N__call__)NotImplementedError)rargs parsed_argsr r r r=tszBaseAliasCommand.__call__cCs|jSr!r;rr r r namewszBaseAliasCommand.namecCs ||_dSr!rA)rvaluer r r rB{s N) rr r _UNDOCUMENTEDrr=propertyrBsetterr r r r r:ds  r:csHeZdZddgZ dfdd ZddZdd Zd d Zd d ZZ S)r2debugprofileNcs.tt|||||_||_||_||_dS)aCommand for a `toplevel` subcommand alias :type alias_name: string :param alias_name: The name of the alias :type alias_value: string :param alias_value: The parsed value of the alias. This can be retrieved from `AliasLoader.get_aliases()[alias_name]` :type session: botocore.session.Session :param session: The botocore session :type command_table: dict :param command_table: The command table containing all of the possible service command objects that a particular alias could redirect to. :type parser: awscli.argparser.MainArgParser :param parser: The parser to parse commands provided at the top level of a CLI command which includes service commands and global parameters. This is used to parse the service command and any global parameters from the alias's value. :type shadow_proxy_command: CLICommand :param shadow_proxy_command: A built-in command that potentially shadows the alias in name. If the alias references this command in its value, the alias should proxy to this command as oppposed to proxy to itself in the command table N)superr2rr)_command_table_parser_shadow_proxy_command)rr5r6r+r3r4shadow_proxy_command __class__r r rs   zServiceAliasCommand.__init__cCs|}|j|\}}|||||td|j||j|j |j}|j r?|j j }||jkr?td|j |j|j }|||S)Nz/Alias %r passing on arguments: %r to %r commandz/Using shadowed command object: %s for alias: %s) _get_alias_argsrKparse_known_args_update_parsed_globalsextendLOGrGr;commandrJrLrB)rr?parsed_globals alias_argsparsed_alias_args remainingrU shadow_namer r r r=s*      zServiceAliasCommand.__call__c Csfzt|j}Wnty}z td|j||jfd}~wwdd|D}td|j|j||S)NzLValue of alias "%s" could not be parsed. Received error: %s when parsing: %scSsg|]}|tjqSr )r"rlinesep).0argr r r sz7ServiceAliasCommand._get_alias_args..z2Expanded subcommand alias %r with value: %r to: %r)shlexsplitr< ValueErrorrr;rTrG)rrWer r r rPs"  z#ServiceAliasCommand._get_alias_argscCs:||}t|j||D] }t||}t|||q dSr!) _get_global_parameters_to_updaterr)getattrsetattr)rrXrVglobal_params_to_update param_nameupdated_param_valuer r r rRs  z*ServiceAliasCommand._update_parsed_globalscCsTg}t|D]\}}|j||kr'||jvr"td||jf||q|S)NzZGlobal parameter "--%s" detected in alias "%s" which is not support in subcommand aliases.)varsr.rK get_defaultUNSUPPORTED_GLOBAL_PARAMETERSrr;r1)rrXrf parsed_paramrCr r r rcs  z4ServiceAliasCommand._get_global_parameters_to_updater!) rr r rkrr=rPrRrc __classcell__r r rNr r2s& r2c@s"eZdZejfddZddZdS)r0cCs||_||_||_dS)a0Command for external aliases Executes command external of CLI as opposed to being a proxy to another command. :type alias_name: string :param alias_name: The name of the alias :type alias_value: string :param alias_value: The parsed value of the alias. This can be retrieved from `AliasLoader.get_aliases()[alias_name]` :type invoker: callable :param invoker: Callable to run arguments of external alias. The signature should match that of ``subprocess.call`` N)r;r<_invoker)rr5r6invokerr r r rs zExternalAliasCommand.__init__cCsP|jddg}|dd|Dd|}td|j|j||j|ddS)Ncss|]}t|VqdSr!r)r\ar r r sz0ExternalAliasCommand.__call__.. z1Using external alias %r with value: %r to run: %rT)shell)r<rSr&rTrGr;rn)rr?rVcommand_componentsrUr r r r=s   zExternalAliasCommand.__call__N)rr r subprocesscallrr=r r r r r0s r0)loggingrr_rvbotocore.configloaderr awscli.compatrawscli.commandsr awscli.utilsr getLoggerrrT Exceptionrobjectr r'r:r2r0r r r r s      ""|