o 2&a5@sddlZddlZddlZddlZddlZddlmZmZddlm Z ddl m Z ddl m Z ddl mZddl mZddl mZdd l mZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZe dZ!Gddde"Z#ddZ$Gddde%Z&Gddde&Z'Gddde&Z(Gddde%Z)Gddde)Z*Gd d!d!e)Z+Gd"d#d#e)Z,Gd$d%d%e)Z-Gd&d'd'e)Z.dS)(N)PopenPIPE)publish_string)manpage)ProviderDocumentEventHandler)ServiceDocumentEventHandler)OperationDocumentEventHandler)TopicListerDocumentEventHandler)TopicDocumentEventHandler) docevents) ReSTDocument) TextWriter)ParamShorthandParser)ArgTableArgParser) TopicTagDB) ignore_ctrl_cz awscli.helpcseZdZfddZZS)ExecutableNotFoundErrorcstt|d|dS)Nz$Could not find executable named "%s")superr__init__)selfexecutable_name __class__-/usr/lib/python3/dist-packages/awscli/help.pyr)s z ExecutableNotFoundError.__init__)__name__ __module__ __qualname__r __classcell__rrrrr(srcCstdkr tStS)zZ Return the appropriate HelpRenderer implementation for the current platform. Windows)platformsystemWindowsHelpRendererPosixHelpRendererrrrr get_renderer.s r$c@sJeZdZdZejfddZdZddZddZ d d Z d d Z d dZ dS)PagingHelpRendererz Interface for a help renderer. The renderer is responsible for displaying the help content on a particular platform. cCs ||_dSN) output_stream)rr'rrrrAs zPagingHelpRenderer.__init__NcCs:|j}dtjvrtjd}n dtjvrtjd}t|S)NMANPAGERPAGER)r)osenvironshlexsplit)rpagerrrrget_pager_cmdlineFs      z$PagingHelpRenderer.get_pager_cmdlinecCs||}||dS)z` Each implementation of HelpRenderer must implement this render method. N)_convert_doc_content_send_output_to_pager)rcontentsconverted_contentrrrrenderNs zPagingHelpRenderer.rendercCs2|}td||j|td}|j|ddS)NRunning command: %sstdininput)r/LOGdebug_popenr communicateroutputcmdlineprrrr1Vs z(PagingHelpRenderer._send_output_to_pagercOst|i|Sr&rrargskwargsrrrr<\szPagingHelpRenderer._popencCs|Sr&r)rr2rrrr0_sz'PagingHelpRenderer._convert_doc_content) rrr__doc__sysstdoutrr)r/r4r1r<r0rrrrr%9s r%c@s,eZdZdZdZddZddZddZd S) r#z[ Render help content on a Posix-like system. This includes Linux and MacOS X. zless -RcCs\t|td}|dstdgd}td||j|tttd}|j |dd}|S)Nwritergroff)rKz-mmanz-Tasciir5)r7rHstderrr8r) rrWriter_exists_on_pathrr:r;r<rr=)rr2 man_contentsr@p3 groff_outputrrrr0ks  z&PosixHelpRenderer._convert_doc_contentcCs|}||ds&td|d|j|dd|jdStd|t|j |t d}|j |dWddS1sHwYdS)Nrz0Pager '%s' not found in PATH, printing raw help.zutf-8 r5r6r8) r/rPr:r;r'writedecodeflushrr<rr=r>rrrr1us   "z'PosixHelpRenderer._send_output_to_pagercs(tfddtjddtjDS)Ncs"g|] }tjtj|qSr)r*pathexistsjoin).0rAnamerr sz5PosixHelpRenderer._exists_on_path..PATH)anyr*r+getr-pathsep)rr]rr\rrPs z!PosixHelpRenderer._exists_on_pathN)rrrrFr)r0r1rPrrrrr#cs  r#c@s$eZdZdZdZddZddZdS)r"z*Render help content on a Windows platform.morecCst|td}|S)NrI)rr )rr2 text_outputrrrr0sz(WindowsHelpRenderer._convert_doc_contentcOsd|d<t|i|S)NTshellrBrCrrrr<szWindowsHelpRenderer._popenN)rrrrFr)r0r<rrrrr"s  r"c@sVeZdZdZdZ ddZeddZeddZed d Z ed d Z d dZ dS) HelpCommandak HelpCommand Interface --------------------- A HelpCommand object acts as the interface between objects in the CLI (e.g. Providers, Services, Operations, etc.) and the documentation system (bcdoc). A HelpCommand object wraps the object from the CLI space and provides a consistent interface to critical information needed by the documentation pipeline such as the object's name, description, etc. The HelpCommand object is passed to the component of the documentation pipeline that fires documentation events. It is then passed on to each document event handler that has registered for the events. All HelpCommand objects contain the following attributes: + ``session`` - A ``botocore`` ``Session`` object. + ``obj`` - The object that is being documented. + ``command_table`` - A dict mapping command names to callable objects. + ``arg_table`` - A dict mapping argument names to callable objects. + ``doc`` - A ``Document`` object that is used to collect the generated documentation. In addition, please note the `properties` defined below which are required to allow the object to be used in the document pipeline. Implementations of HelpCommand are provided here for Provider, Service and Operation objects. Other implementations for other types of objects might be needed for customization in plugins. As long as the implementations conform to this basic interface it should be possible to pass them to the documentation system and generate interactive and static help files. NcCsT||_||_|dur i}||_|duri}||_i|_g|_t|_tdd|_ dS)NrL)target) sessionobj command_table arg_table_subcommand_table_related_itemsr$rendererr doc)rrirjrkrlrrrrszHelpCommand.__init__cCdS)aX Return the ``event_class`` for this object. The ``event_class`` is used by the documentation pipeline when generating documentation events. For the event below:: doc-title.. The document pipeline would use this property to determine the ``event_class`` value. Nrrrrr event_classs zHelpCommand.event_classcCrq)z Return the name of the wrapped object. This would be called by the document pipeline to determine the ``name`` to be inserted into the event, as shown above. Nrrrrrrr]szHelpCommand.namecC|jS)z=These are the commands that may follow after the help command)rmrrrrrsubcommand_tablezHelpCommand.subcommand_tablecCrt)z:This is list of items that are related to the help command)rnrrrrr related_itemsrvzHelpCommand.related_itemscCsv|r ti|j}||\}}t|dddur |j|j||S||}t|j||j |j | dS)N subcommand)rruparse_known_argsgetattrrxEventHandlerClassr generate_eventsriror4rpgetvalue unregister)rrDparsed_globalssubcommand_parserparsed remaininginstancerrr__call__s    zHelpCommand.__call__) rrrrFr{rpropertyrsr]rurwrrrrrrgs%     rgc@sHeZdZdZeZddZeddZeddZ edd Z d d Z d S) ProviderHelpCommandz^Implements top level help command. This is what is called when ``aws help`` is run. cCs<t||d||||_||_||_d|_d|_dg|_dS)Nzaws help topics)rgr descriptionsynopsis help_usagerm _topic_tag_dbrn)rrirkrlrrusagerrrrs  zProviderHelpCommand.__init__cCrqNawsrrrrrrrs'zProviderHelpCommand.event_classcCrqrrrrrrrr]+rzProviderHelpCommand.namecCs6|jdur|jdurt|_|j||_|jSr&)rmrrload_json_index_create_subcommand_tablerrrrrru/s    z$ProviderHelpCommand.subcommand_tablecCsBi}t|j}||d<|j}|D] }t|j|}|||<q|SNtopics)TopicListerCommandrirget_all_topic_namesTopicHelpCommand)rrutopic_lister_command topic_names topic_nametopic_help_commandrrrr8s    z,ProviderHelpCommand._create_subcommand_tableN) rrrrFrr{rrrsr]rurrrrrrs    rcs<eZdZdZeZfddZeddZeddZ Z S)ServiceHelpCommandzImplements service level help. This is the object invoked whenever a service command help is implemented, e.g. ``aws ec2 help``. cs&tt|||||||_||_dSr&)rrr_name _event_class)rrirjrkrlr]rsrrrrPs  zServiceHelpCommand.__init__cCrtr&rrrrrrrsWzServiceHelpCommand.event_classcCrtr&rrrrrrr][rzServiceHelpCommand.name) rrrrFrr{rrrsr]rrrrrrFs  rc@s4eZdZdZeZddZeddZeddZ dS) OperationHelpCommandzImplements operation level help. This is the object invoked whenever help for a service is requested, e.g. ``aws ec2 describe-instances help``. cCs*t|||d|t|_||_||_dSr&)rgrrparam_shorthandrr)rrioperation_modelrlr]rsrrrris zOperationHelpCommand.__init__cCrtr&rrrrrrrsprz OperationHelpCommand.event_classcCrtr&rrrrrrr]trzOperationHelpCommand.nameN) rrrrFrr{rrrsr]rrrrr`s rc8eZdZeZfddZeddZeddZZ S)rcstt||diidSr&)rrr)rrirrrr|szTopicListerCommand.__init__cCrqrrrrrrrrsrzTopicListerCommand.event_classcCrqrrrrrrrr]rzTopicListerCommand.name) rrrr r{rrrsr]rrrrrrys  rcr)rcs tt||dii||_dSr&)rrr _topic_name)rrirrrrrs zTopicHelpCommand.__init__cCs d|jS)Nztopics.r\rrrrrrss zTopicHelpCommand.event_classcCrtr&)rrrrrrr]rzTopicHelpCommand.name) rrrr r{rrrsr]rrrrrrs  r)/loggingr*rGr r, subprocessrr docutils.corerdocutils.writersrawscli.clidocsrrrr r awscli.bcdocr awscli.bcdoc.restdocr awscli.bcdoc.textwriterr awscli.argprocessrawscli.argparserrawscli.topictagsr awscli.utilsr getLoggerr: Exceptionrr$objectr%r#r"rgrrrrrrrrrs@                 *1o2