
    5pj	                    2   S r SSKJr  SSKrSSKJrJr  SSKJrJ	r	  SSK
JrJr  SSKJrJr  SS	KJr  SS
KJr  SSKJr   " S S\5      r " S S\5      rSS jrSSSSS.           SS jjrSS jrSS jrSS jrSS jrS S jrS!S jr S"S jr!/ SQr"g)#a  Base contracts and shared helpers for ``modelscope`` CLI subcommands.

Every concrete subcommand is a small, self-contained class that:

1. Registers its argparse parser via :meth:`CLICommand.register`.
2. Receives the parsed ``argparse.Namespace`` in its constructor.
3. Performs its work in :meth:`CLICommand.execute`.

This keeps :mod:`.main` free of subcommand-specific logic and makes adding
a new command a single-file change.
    )annotationsN)ABCabstractmethod)ArgumentParser	Namespace)IterableSequence)AnyProtocol   )HubApi)RepoType)tabulatec                  "    \ rS rSrSrSS jrSrg)
SubParsers   a  Structural stand-in for ``argparse._SubParsersAction``.

argparse only exposes its sub-parsers container as a private class, so
commands accept anything that provides ``add_parser`` instead. This keeps
both mypy and IDE inspections happy without referencing private names.
c                    g N )selfnamekwargss      S/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/modelscope_hub/cli/base.py
add_parserSubParsers.add_parser%   s    c    r   N)r   strr   r
   returnr   )__name__
__module____qualname____firstlineno____doc__r   __static_attributes__r   r   r   r   r      s     Jr   r   c                  T    \ rS rSrSrSS jr\\S	S j5       5       r\S
S j5       r	Sr
g)
CLICommand+   z2Abstract contract every CLI subcommand implements.c                    Xl         g r   args)r   r*   s     r   __init__CLICommand.__init__.   s    	r   c                    g)z8Attach this command's argparse parser to ``subparsers``.Nr   )
subparserss    r   registerCLICommand.register1       r   c                    g)z4Run the command. Raise on failure; print on success.Nr   )r   s    r   executeCLICommand.execute6   r1   r   r)   N)r*   r   r   None)r.   r   r   r5   r   r5   )r   r    r!   r"   r#   r+   staticmethodr   r/   r3   r$   r   r   r   r&   r&   +   s>    < G  G C Cr   r&   c                    [        U SS5      nU(       a  Xl        [        U SS5      nU(       a  X l        [        [        U SS5      [        U SS5      S9$ )zConstruct a :class:`HubApi` honouring global and subcommand ``--token`` / ``--endpoint``.

Automatically merges subcommand-level ``subcmd_token``/``subcmd_endpoint``
into the namespace (subcommand values take precedence over global values).
subcmd_tokenNsubcmd_endpointtokenendpoint)r;   r<   )getattrr;   r<   r   )r*   r9   r:   s      r   make_apir>   >   sV     46L!
d$5t<O'dGT*z40 r   TzRepository type.)choicesdefaultrequiredhelpc          
         U(       a  [        U5      O[         Vs/ s H  oUR                  PM     snnU R                  SSSUUU=(       a    USL US9  gs  snf )zAttach a uniform ``--repo-type`` argument to ``parser``.

Also accepts the legacy ``--repo_type`` (underscore) form for backward
compatibility with the old ``modelscope`` CLI.
z--repo-typez--repo_type	repo_typeN)destr?   r@   rA   rB   )listr   valueadd_argument)parserr?   r@   rA   rB   tvalids          r   add_repo_type_argrL   Q   sY     %DMH*EHq77H*EE
-go   +Fs   Ac                    [        U 5        g)zPrint a neutral status line.N)printmessages    r   inforQ   m   s	    	'Nr   c                p    [         R                  R                  5       (       a  SOSn[        U U  35        g)u>   Print a success line (prefixed with ✓ when stdout is a TTY).u   ✓  N)sysstdoutisattyrN   )rP   prefixs     r   successrX   r   s,    zz((**VF	VHWI
r   c                :    [        SU  3[        R                  S9  g)zPrint a warning line to stderr.z	warning: fileNrN   rT   stderrrO   s    r   warnr^   x   s    	IgY
cjj1r   c                :    [        SU  3[        R                  S9  g)zPrint an error line to stderr.zerror: rZ   Nr\   rO   s    r   errorr`   }   s    	GG9
CJJ/r   c                    [        X5      $ )z(Format rows as a fixed-width text table.)	_tabulate)rowsheaderss     r   render_tablere      s    T##r   c                    0 nU  HX  nSU;  a  [        SU< S35      eUR                  S5      u  p4nUR                  5       nU(       d  [        SU< S35      eXQU'   MZ     U$ )zrParse ``key=value`` argument tokens into a dict.

Raises :class:`ValueError` when a token does not contain ``=``.
=zInvalid setting z: expected 'key=value' format.z: empty key.)
ValueError	partitionstrip)valuesresultrawkey_rG   s         r   parse_kv_pairsrp      ss    
  Fc>/w6TUVVc*iik/wlCDDs  Mr   c                    SSK n SSKJn  SSKJnJn  U" [        5      nU H   nXER                     R                  U5        M"     U GH  nUR                  U5      nU(       d  M  [        SU S35        / nU H  n	U R                  R                  U	R                  5      n
SnU
cH  U	R                  (       a7  U	R                   H'  nU R                  R                  U5      nUc  M#  Un
Un  O   U
b  U
OSnU(       a	  US	U S
3-  nUR                  U	R                  XR                  U	R                  45        M     [        [!        U/ SQS95        GM     g)zAPrint all configurable environment variables grouped by category.r   N)defaultdictr   )CATEGORY_ORDERENV_REGISTRYz
[]z	(not set)z  (via deprecated ))VariableCurrentDefaultDescription)rd   )oscollectionsrr   	constantsrs   rt   rF   categoryappendgetrQ   environr   deprecated_namesr@   descriptionre   )r{   rr   rs   rt   groupsentrycatentriesrc   ecurrentdeprecated_in_useoldvaldisplays                  r   print_env_tabler      s(   '8)$/F~~%%e,  **S/s3%q\AjjnnQVV,G $1#5#5--C**..-C"%,/) . ")!4g+G /0A/B!DDKK))Q]]CD  	\$(YZ[) r   )
r&   rL   r`   rQ   r>   rp   r   re   rX   r^   )r*   r   r   r   )rI   r   r?   zSequence[str] | Noner@   z
str | NonerA   boolrB   r   r   r5   )rP   r   r   r5   )rc   zIterable[Sequence[Any]]rd   zSequence[str]r   r   )rk   zIterable[str]r   zdict[str, str]r6   )#r#   
__future__r   rT   abcr   r   argparser   r   collections.abcr   r	   typingr
   r   apir   r}   r   utils.formatr   rb   r   r&   r>   rL   rQ   rX   r^   r`   re   rp   r   __all__r   r   r   <module>r      s   
 # 
 # . .      0J JC C&, %)" " 	
   
8
 2
0
$
"\Dr   