o ]Lb7-@sddlmZddlZddlZddlmZddlmZmZhdZ ddZ dd d Z Gd d d e Z Gddde ZGddde ZGddde ZGddde ZddZdddZdS))absolute_importN)_)errorpycompat>helpversionnoninteractivecCs|dr1|d\}}}|dd|vr|t||dfS|ddd|vr/|t||dfSd S|drg|dkrg|dsg|dd|dd}}||d d}|d krg|t|||d |d fSd S) aCheck 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-:rr:)FrF) startswith partitionboolfind)arg shortlistnamelistflageqvalir5/usr/lib/python3/dist-packages/mercurial/fancyopts.py _earlyoptargs 1rFc Csg}g}d}|t|kri||}|dkr|| 7}nOt|||\} } } } | s1| r1|dt|kr1n8| r7| rD| sD|rC|||d7}n n%| | krT|| | f|d7}n|| ||df|d7}|t|ks |||d||fS)as 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']) rr rr N)lenrappendextend) argsrrgnukeepsep parsedopts parsedargsposrrhasvalrtakevalrrr earlygetopt^s0R       r)c@s<eZdZdZejZddZddZddZ ej dd Z d S) customoptz2Manage defaults and mutations for any type of opt.cCs ||_dSN _defaultvalue)self defaultvaluerrr__init__ zcustomopt.__init__cCdS)NFrr.rrr _isbooloptzcustomopt._isbooloptcCs|jS)zReturns the default value for this opt. Subclasses should override this to return a new value if the value type is mutable.r,r3rrrgetdefaultvalueszcustomopt.getdefaultvaluecCr2)zzAdds newparam to oldstate and returns the new state. On failure, abort can be called with a string error message.Nrr.oldstatenewparamabortrrrnewstateszcustomopt.newstateN) __name__ __module__ __qualname____doc__abcABCMeta __metaclass__r0r4r6abstractmethodr;rrrrr*sr*c@eZdZddZddZdS) _simpleoptcCst|jttdfSr+) isinstancer-rtyper3rrrr4sz_simpleopt._isbooloptcCs|Sr+rr7rrrr;r5z_simpleopt.newstateN)r<r=r>r4r;rrrrrE rEcs$eZdZfddZddZZS) _callableoptcs||_tt|ddSr+) callablefnsuperrIr0)r.rJ __class__rrr0sz_callableopt.__init__cCs ||Sr+)rJr7rrrr;r1z_callableopt.newstate)r<r=r>r0r; __classcell__rrrLrrIs rIc@rD)_listoptcCs|jddSr+r,r3rrrr6sz_listopt.getdefaultvaluecCs|||Sr+)rr7rrrr;s z_listopt.newstateN)r<r=r>r6r;rrrrrOrHrOc@seZdZddZdS)_intoptcCs,zt|WSty|tdYdSw)Ns expected int)int ValueErrorrr7rrrr;s   z_intopt.newstateN)r<r=r>r;rrrrrPs rPcCsXt|tr|St|rt|St|trt|ddSt|tdur(t|St|S)z=zfancyopts..r _r rcSsg|]}|dqS)r r)rWnrrr UrZzfancyopts..sno-)r"TFcsttdt|f)Ns"invalid value %r for option %s, %s)r InputErrorrr maybebytestr)soptrrrr:~s zfancyopts..abort)rr getreplacerVr6r4 nevernegaterr functoolspartialr)r gnugetoptbgetoptbr;)r!optionsstater"early optaliasesrrargmapdefmap negationsalllongoptionshortnamerUcommentdummyonamesr]insertparseoptsboolvalnegationobjr:rrcr fancyoptsst            r)FF)FFN) __future__rr@rhi18nrrrrgrr)objectr*rErIrOrPrVrrrrrs   ?r