a [f$*@sdZddlZddlZddlZddlZddlZddlmZddlm Z m Z m Z m Z m Z ddlmZddlmZmZddlmZmZeeZGdd d ejZGd d d eZGd d d ejZGdddeZdS)zBase option parser setupN)suppress)AnyDictIteratorListTuple) UNKNOWN_ERROR) ConfigurationConfigurationError)redact_auth_from_url strtoboolcseZdZdZeeddfdd ZejedddZ dejeeed d d Z eedddZ eedddZ eedddZ eedddZeeedddZZS)PrettyHelpFormatterz4A prettier/less verbose help formatter for optparse.N)argskwargsreturncs:d|d<d|d<tdd|d<tj|i|dS)Nmax_help_positionindent_incrementrwidth)shutilget_terminal_sizesuper__init__)selfrr __class__, )r!mvarfmtoptseprcCsg}|jr||jd|jr0||jdt|dkrH|d||r|jdus^J|jpl|j}|| |d |S)z Return a comma-separated list of option strings and metavars. :param option: tuple of (short opt, long opt), e.g: ('-f', '--format') :param mvarfmt: metavar format string :param optsep: separator rrN) Z _short_optsappendZ _long_optsleninsertZ takes_valuedestmetavarlowerformatjoin)rr!r'r(Zoptsr.rrrr#s   z*PrettyHelpFormatter._format_option_strings)headingrcCs|dkr dS|dS)NZOptionsr): r)rr2rrrformat_heading9sz"PrettyHelpFormatter.format_heading)usagercCsd|t|d}|S)zz Ensure there is only one newline between usage and the first heading if there is no description. z Usage: {}  )r0 indent_linestextwrapdedent)rr5msgrrr format_usage>sz PrettyHelpFormatter.format_usage) descriptionrcCsZ|rRt|jdrd}nd}|d}|}|t|d}|d|d}|SdSdS)NmainZCommandsZ Description r6r3r))hasattrparserlstriprstripr7r8r9)rr<Zlabelrrrformat_descriptionFs  z&PrettyHelpFormatter.format_description)epilogrcCs|r|SdSdS)Nr)r)rrDrrr format_epilogXsz!PrettyHelpFormatter.format_epilog)textindentrcs"fdd|dD}d|S)Ncsg|] }|qSrr).0linerGrr `z4PrettyHelpFormatter.indent_lines..r>)splitr1)rrFrGZ new_linesrrJrr7_sz PrettyHelpFormatter.indent_lines)r%r&)__name__ __module__ __qualname____doc__rroptparseOptionstrr$r#r4r;rCrEr7 __classcell__rrrrr s r cs*eZdZdZejedfdd ZZS)UpdatingDefaultsHelpFormatterzCustom help formatter for use in ConfigOptionParser. This is updates the defaults before expanding them, allowing them to show up correctly in the help listing. Also redact auth from url type options r csd}|jdurLt|jtsJ|j|jj|jdustd|q$|dd\}}||vr$||||fq$|D] }||D]\}}||fVqzqndS)Nglobalz:env:cSsi|] }|gqSrr)rHrorrr szGConfigOptionParser._get_ordered_configuration_items..z7Ignoring configuration key '%s' as it's value is empty..r)rorpitemsloggerdebugrMr*)rZoverride_orderZ section_itemsZ section_keyr`sectionrqrrr _get_ordered_configuration_itemss" z3ConfigOptionParser._get_ordered_configuration_items)rZrc stj_t}D]\}ddur>qjdusLJjdvrz t |}Wn$t y d |Yn0nDjdkr"t t t |}Wdn1s0Yt t t|}Wdn1s0Yt|tr|dkrЈ d |njdkrN|}fd d |D}njd krˆjdusjJ|j}||}jpd }jpi}j||g|Ri|n|}||j<q|D]tj|<qd_|S) zUpdates the given defaults with values from the config files and the environ. Does a little special handling for certain types of options (lists).z--N) store_true store_falsezm{} is not a valid value for {} option, please specify a boolean value like yes/no, true/false or 1/0 instead.countrz{} is not a valid value for {} option, please instead specify either a non-negative integer or a boolean value like yes/no or false/true which is equivalent to 1/0.r*csg|]}|qSr)rx)rHvrqr!rrrrKrLz7ConfigOptionParser._update_defaults..callbackr)rRValuesrZvaluessetrZ get_optionr-actionr ValueErrorerrorr0rrlrWrMraddget_opt_stringZ convert_valueZ callback_argsZcallback_kwargsrxgetattr)rrZZ late_evalr`opt_strrrrrrrYsX     & &        z#ConfigOptionParser._update_defaultsc Cs|jst|jSz|jWn4tyT}z|tt |WYd}~n d}~00| |j }| D]B}|j dusJ||j }t|t rn|}|||||j <qnt|S)zOverriding to make updating the defaults after instantiation of the option parser possible, _update_defaults() does the dirty work.N)Zprocess_default_valuesrRrrZrploadr rvrrTrYcopyZ_get_all_optionsr-r[rWrrs)rerrrZr!defaultrrrrget_default_values s &   z%ConfigOptionParser.get_default_values)r:rcCs"|tj|t|ddS)Nr>) print_usagerustderrrvr)rr:rrrr"s zConfigOptionParser.error)rNrOrPrQrrTboolrrRrSrxrrrrrYrrrrUrrrrrXs  @rX)rQZloggingrRrrur8 contextlibrtypingrrrrrZpip._internal.cli.status_codesrZpip._internal.configurationr r Zpip._internal.utils.miscr r Z getLoggerrNr}ZIndentedHelpFormatterr rVZ OptionParserrarXrrrrs   R