
    6h-                        S SK Jr  S SKrS SKrSSKJr  SSKJrJr  1 Skr	S r
SS jr " S	 S
5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      rS rSS jrg)    )annotationsN   )_)errorpycompat>      help   version   noninteractivec                   U R                  S5      (       aI  U R                  S5      u  p4nUSS U;   a  U[        U5      US4$ USS S-   U;   a  U[        U5      US4$  gU R                  S5      (       a`  U S:w  aZ  U R                  S5      (       dD  U SS U SS pSUR                  US	S 5      nUS
:  a!  U[        U5      XQR                  SUS	-   5      4$ g)a  Check if the given arg is a valid unabbreviated option

Returns (flag_str, has_embedded_value?, embedded_value, takes_value?)

>>> def opt(arg):
...     return _earlyoptarg(arg, b'R:q', [b'cwd=', b'debugger'])

long form:

>>> opt(b'--cwd')
('--cwd', False, '', True)
>>> opt(b'--cwd=')
('--cwd', True, '', True)
>>> opt(b'--cwd=foo')
('--cwd', True, 'foo', True)
>>> opt(b'--debugger')
('--debugger', False, '', False)
>>> opt(b'--debugger=')  # invalid but parsable
('--debugger', True, '', False)

short form:

>>> opt(b'-R')
('-R', False, '', True)
>>> opt(b'-Rfoo')
('-R', True, 'foo', True)
>>> opt(b'-q')
('-q', False, '', False)
>>> opt(b'-qfoo')  # invalid but parsable
('-q', True, 'foo', False)

unknown or invalid:

>>> opt(b'--unknown')
('', False, '', False)
>>> opt(b'-u')
('', False, '', False)
>>> opt(b'-ufoo')
('', False, '', False)
>>> opt(b'--')
('', False, '', False)
>>> opt(b'-')
('', False, '', False)
>>> opt(b'-:')
('', False, '', False)
>>> opt(b'-:foo')
('', False, '', False)
   --   =   NFT   -s   -:r   r      :)    Fr   F)
startswith	partitionboolfind)arg	shortlistnamelistflageqvalis          5/usr/lib/python3/dist-packages/mercurial/fancyopts.py_earlyoptargr      s    b ~~ed+#8xb3--8d?h&b3,, ' " 
		#+cnnU6K6KGSWcNN48$6cC)=)=dAE)JJJ!r   c                   / n/ nSnU[        U 5      :  a  X   nUS:X  a
  Xt(       + -  nO[        XU5      u  ppU
(       d  U(       a  US-   [        U 5      :  a  OU	(       a  U
(       a&  U(       d  U(       a  UR                  U5        US-  nO;OKX:X  a  UR                  X45        US-  nOUR                  XUS-      45        US-  nU[        U 5      :  a  M  UR                  XS 5        XV4$ )a	  Parse options like getopt, but ignores unknown options and abbreviated
forms

If gnu=False, this stops processing options as soon as a non/unknown-option
argument is encountered. Otherwise, option and non-option arguments may be
intermixed, and unknown-option arguments are taken as non-option.

If keepsep=True, '--' won't be removed from the list of arguments left.
This is useful for stripping early options from a full command arguments.

>>> def get(args, gnu=False, keepsep=False):
...     return earlygetopt(args, b'R:q', [b'cwd=', b'debugger'],
...                        gnu=gnu, keepsep=keepsep)

default parsing rules for early options:

>>> get([b'x', b'--cwd', b'foo', b'-Rbar', b'-q', b'y'], gnu=True)
([('--cwd', 'foo'), ('-R', 'bar'), ('-q', '')], ['x', 'y'])
>>> get([b'x', b'--cwd=foo', b'y', b'-R', b'bar', b'--debugger'], gnu=True)
([('--cwd', 'foo'), ('-R', 'bar'), ('--debugger', '')], ['x', 'y'])
>>> get([b'--unknown', b'--cwd=foo', b'--', '--debugger'], gnu=True)
([('--cwd', 'foo')], ['--unknown', '--debugger'])

restricted parsing rules (early options must come first):

>>> get([b'--cwd', b'foo', b'-Rbar', b'x', b'-q', b'y'], gnu=False)
([('--cwd', 'foo'), ('-R', 'bar')], ['x', '-q', 'y'])
>>> get([b'--cwd=foo', b'x', b'y', b'-R', b'bar', b'--debugger'], gnu=False)
([('--cwd', 'foo')], ['x', 'y', '-R', 'bar', '--debugger'])
>>> get([b'--unknown', b'--cwd=foo', b'--', '--debugger'], gnu=False)
([], ['--unknown', '--cwd=foo', '--', '--debugger'])

stripping early options (without loosing '--'):

>>> get([b'x', b'-Rbar', b'--', '--debugger'], gnu=True, keepsep=True)[1]
['x', '--', '--debugger']

last argument:

>>> get([b'--cwd'])
([], ['--cwd'])
>>> get([b'--cwd=foo'])
([('--cwd', 'foo')], [])
>>> get([b'-R'])
([], ['-R'])
>>> get([b'-Rbar'])
([('-R', 'bar')], [])
>>> get([b'-q'])
([('-q', '')], [])
>>> get([b'-q', b'--'])
([('-q', '')], [])

'--' may be a value:

>>> get([b'-R', b'--', b'x'])
([('-R', '--')], ['x'])
>>> get([b'--cwd', b'--', b'x'])
([('--cwd', '--')], ['x'])

value passed to bool options:

>>> get([b'--debugger=foo', b'x'])
([], ['--debugger=foo', 'x'])
>>> get([b'-qfoo', b'x'])
([], ['-qfoo', 'x'])

short option isn't separated with '=':

>>> get([b'-R=bar'])
([('-R', '=bar')], [])

':' may be in shortlist, but shouldn't be taken as an option letter:

>>> get([b'-:', b'y'])
([], ['-:', 'y'])

'-' is a valid non-option argument:

>>> get([b'-', b'y'])
([], ['-', 'y'])
r   r   r   r   N)lenr   appendextend)argsr   r   gnukeepsep
parsedopts
parsedargsposr   r   hasvalr   takevals                r   earlygetoptr+   ^   s    d JJ
C
D	/i%<;C%1#(%K"c'cAgT&:vg!!#&qtk*1HC t#']341HC/ D	/2 d4j!!!r   c                  f    \ rS rSrSr\R                  rS rS r	S r
\R                  S 5       rSrg)		customopt   z2Manage defaults and mutations for any type of opt.c                    Xl         g N_defaultvalue)selfdefaultvalues     r   __init__customopt.__init__   s    )r   c                    g)NF r3   s    r   
_isbooloptcustomopt._isboolopt   s    r   c                    U R                   $ )z|Returns the default value for this opt.

Subclasses should override this to return a new value if the value type
is mutable.r1   r9   s    r   getdefaultvaluecustomopt.getdefaultvalue   s    
 !!!r   c                    g)zrAdds newparam to oldstate and returns the new state.

On failure, abort can be called with a string error message.Nr8   r3   oldstatenewparamaborts       r   newstatecustomopt.newstate   s    r   r1   N)__name__
__module____qualname____firstlineno____doc__abcABCMeta__metaclass__r5   r:   r=   abstractmethodrD   __static_attributes__r8   r   r   r-   r-      s9    <KKM*" 	H Hr   r-   c                       \ rS rSrS rS rSrg)
_simpleopt   c                L    [        U R                  [        [        S 5      45      $ r0   )
isinstancer2   r   typer9   s    r   r:   _simpleopt._isboolopt   s    $,,tT$Z.@AAr   c                    U$ r0   r8   r@   s       r   rD   _simpleopt.newstate   s    r   r8   N)rF   rG   rH   rI   r:   rD   rO   r8   r   r   rQ   rQ      s    Br   rQ   c                  .   ^  \ rS rSrU 4S jrS rSrU =r$ )_callableopt   c                0   > Xl         [        TU ]	  S 5        g r0   )
callablefnsuperr5   )r3   r]   	__class__s     r   r5   _callableopt.__init__   s    $r   c                $    U R                  U5      $ r0   r]   r@   s       r   rD   _callableopt.newstate   s    x((r   rb   )rF   rG   rH   rI   r5   rD   rO   __classcell__)r_   s   @r   rZ   rZ      s    ) )r   rZ   c                       \ rS rSrS rS rSrg)_listopt   c                     U R                   S S  $ r0   r1   r9   s    r   r=   _listopt.getdefaultvalue   s    !!!$$r   c                (    UR                  U5        U$ r0   )r!   r@   s       r   rD   _listopt.newstate   s    !r   r8   N)rF   rG   rH   rI   r=   rD   rO   r8   r   r   rf   rf      s    %r   rf   c                      \ rS rSrS rSrg)_intopti  c                \     [        U5      $ ! [         a    U" [        S5      5         g f = f)Ns   expected int)int
ValueErrorr   r@   s       r   rD   _intopt.newstate  s-    	&x=  	&!O$%	&s   
 ++r8   N)rF   rG   rH   rI   rD   rO   r8   r   r   rm   rm     s    &r   rm   c                    [        U [        5      (       a  U $ [        U 5      (       a  [        U 5      $ [        U [        5      (       a  [        U SS 5      $ [        U 5      [        L a  [        U 5      $ [        U 5      $ )z<Returns a default opt implementation, given a default value.N)
rT   r-   callablerZ   listrf   rU   ro   rm   rQ   )defaults    r   _defaultoptrv     sj     '9%%	'		G$$	GT	"	"
##	g#	w'""r   c                  ^^ Uc  0 n/ nSn0 n0 n	0 n
U Vs1 s H  oS   iM	     nnU GHQ  n[        U5      S:X  a  Uu  pnnnOUu  pnnU/nUR                  UR                  U/ 5      5        UR                  SS5      nXSU-   '   U H
  nXSU-   '   M     [	        U5      X'   X   R                  5       X/'   X   R                  5       (       d"  U(       a  US-  nU Vs/ s H  nUS	-   PM
     nnOcU[        ;  aY  U HS  nUR                  S
5      (       a  USS nOS
U-   nUU;  d  M,  SU-   U
;  d   eSU-   U
SU-   '   UR                  U5        MU     U(       a  X~-  nU(       d  GM@  UR                  U5        GMT     U(       a  [        R                  " [        US9nO(U(       a  [        R                  nO[        R                  nU" XU5      u  nn U Hi  u  mmSnU
R                  TS5      nU(       a  UmSnUT   nX   nUR                  5       (       a  UX/'   MI  UU4S jnX   R!                  X/   TU5      X/'   Mk     U $ s  snf s  snf )a"  
read args, parse options, and store options in state

each option is a tuple of:

  short option or ''
  long option
  default value
  description
  option value label(optional)

option types include:

  boolean or none - option sets variable in state to true
  string - parameter string is stored in state
  list - parameter string is added to a list
  integer - parameter strings is stored as int
  function - call function with parameter
  customopt - subclass of 'customopt'

optaliases is a mapping from a canonical option name to a list of
additional long options. This exists for preserving backward compatibility
of early options. If we want to use it extensively, please consider moving
the functionality to the options table (e.g separate long options by '|'.)

non-option args are returned
Nr   r      r      _r   r   r   s   no-   )r$   TFc                v   > [         R                  " [        S5      [        R                  " T5      TU 4-  5      e)Ns"   invalid value %r for option %s, %s)r   
InputErrorr   r   maybebytestr)soptr   s    r   rC   fancyopts.<locals>.abort~  s9    &&;<,,S13:; r   )r    r"   getreplacerv   r=   r:   nevernegater   r!   	functoolspartialr+   r   
gnugetoptbgetoptbrD   )r#   optionsstater$   early
optaliasesr   r   argmapdefmap	negationsoalllongoptionshortnameru   commentdummyonamesninsertparseoptsboolvalnegationobjrC   r   r   s                               @@r   	fancyoptsr     sp   8 
HIFFI$%WtWG%v;!390E'5,2)E'jnnT2./||D$'#te|A $519 "7+ l224 |&&(((./1a$hF/F$<<''qrUF#aZF (!AIi77705	Iefn-OOF+  I4OOF#O T !!+37	##  t1JD$ S==e,CGc{l>>!EK !,//S%HEK% * KU &0 0s   II	)FF)FFN)
__future__r   rK   r   i18nr    r   r   r   r   r+   r-   rQ   rZ   rf   rm   rv   r   r8   r   r   <module>r      ss    # 
  <"~o"dH H2 )9 )y &i &#mr   