a `8añã@shddlZddlZddlZddlmZddlmZddlmZm Z m Z ddl m Z dZ Gd d „d e ƒZdS) éN)Údeepcopyé)Ú Configuration)ÚBooleanSettingÚ ChoiceSettingÚ ListSettingé)ÚSource)ÚCommandLineSourcecsxeZdZd‡fdd„ Zdd„Zdd„Zdd „Zd d „Zd d „Zdd„Z dd„Z dd„Z dd„Z dd„Z ddd„Z‡ZS)r Ncs†tt|ƒ ¡|dur(tjdd…|_n6t|tƒr@t  |¡|_nt|t t fƒrV||_nt dƒ‚||_ |pji|_|pti|_|p~d|_dS)Nrz-arguments must be a string or list of strings©)Úsuperr Ú__init__ÚsysÚargvÚ argumentsÚ isinstanceÚ basestringÚshlexÚsplitÚlistÚtupleÚ TypeErrorÚversionÚoptionsÚparser_optionsÚ positional)Úselfrrrrr©Ú __class__r úS/home/carl/code/landscape/setoptconf-tmp/build/lib/setoptconf/source/commandline.pyr s   zCommandLineSource.__init__cCsT|j|jvr,d|j|jvr,|j|jdSg}d|j ¡ dd¡}| |¡|S)NÚflagsz--%sÚ_ú-)ÚnamerÚlowerÚreplaceÚappend)rÚsettingr Úflagr r rÚ get_flags,s  zCommandLineSource.get_flagscCs.t|tƒr|jrdSdSt|tƒr&dSdSdS)NÚ store_falseÚ store_truer&Ústore)rrÚdefaultr©rr'r r rÚ get_action6s   zCommandLineSource.get_actioncCstjS©N)ÚargparseÚSUPPRESSr.r r rÚ get_default?szCommandLineSource.get_defaultcCs.t|ttfƒrdSt|tƒr$|jjS|jSdSr0)rrrrÚsubtypeÚsanitizer.r r rÚget_typeDs  zCommandLineSource.get_typecCs|jSr0)r#r.r r rÚget_destLszCommandLineSource.get_destcCst|tƒr|jSdSdSr0)rrÚchoicesr.r r rÚ get_choicesOs zCommandLineSource.get_choicescCs0|j|jvr,d|j|jvr,|j|jdSdS)NÚhelp©r#rr.r r rÚget_helpUs zCommandLineSource.get_helpcCs0|j|jvr,d|j|jvr,|j|jdSdS)NÚmetavarr;r.r r rÚ get_metavar[s zCommandLineSource.get_metavarc CsŠ| |¡}| |¡}| |¡}| |¡}| |¡}| |¡}| |¡}| |¡} ||||dœ} |rj|| d<|rv|| d<| r‚| | d<|| fS)N)Úactionr-Údestr:Útyper8r=)r)r/r3r6r7r9r<r>) rr'r r?r-Zargtyper@r8Zarghelpr=Úargument_kwargsr r rÚbuild_argumentas(        üz CommandLineSource.build_argumentc Cs¼t|jƒ}| d¡s"|r"|j|d<tjfi|¤Ž}|jdu}|D]4}| |¡\}}|j|i|¤Ž|r@|jdkr@d}q@|r�|jddd|jd�|j r¸|j D]\} } |j| fi| ¤Žqœ|S)NÚprogrFz --versionz %(prog)s )r?r) rrÚgetr#r1ÚArgumentParserrrCÚ add_argumentr) rÚsettingsÚmanagerrÚparserZ add_versionr'r rBr#rr r rÚ build_parserzs$    ÿzCommandLineSource.build_parserc CsŠ| ||¡}| |j¡}|D]}t||jƒrt||jƒ|_q|jr~|r~i}|jD] \}} t||ƒrPt||ƒ||<qPt|d|ƒt ||d�S)Nr)rHÚparent) rKÚ parse_argsrÚhasattrr#ÚgetattrÚvaluerÚsetattrr) rrHrIrLrJÚparsedr'rr#r!r r rÚ get_config•s      zCommandLineSource.get_config)NNNNN)NN)Ú__name__Ú __module__Ú __qualname__r r)r/r3r6r7r9r<r>rCrKrSÚ __classcell__r r rrr s"ú  r )r1rrÚcopyrÚconfigrr'rrrÚbaser Ú__all__r r r r rÚs