o
    ĎiD                  
   @   s  d Z ddlmZmZ ddlZddlmZ ddlmZ ddl	m
Z
mZmZmZ ddlmZmZmZmZ d	d
lmZmZ eeZeddZejdg dd		d.dedeeejddf ddfddZejdddgd	d/deee ejddf ddfddZdee fddZ ejd d!d"gd		d.deee ejd#df deeejddf ddfd$d%Z!ejd&d'gdd0d(d)Z"ejd*d+gdd0d,d-Z#dS )1a  Contains commands to authenticate to the Hugging Face Hub and interact with your repositories.

Usage:
    # login and save token locally.
    hf auth login --token=hf_*** --add-to-git-credential

    # switch between tokens
    hf auth switch

    # list all tokens
    hf auth list

    # logout from all tokens
    hf auth logout

    # check which account you are logged in as
    hf auth whoami
    )	AnnotatedOptionalN)ENDPOINT)whoami   )	auth_listauth_switchloginlogout)ANSIget_stored_tokens	get_tokenlogging   )TokenOpttyper_factoryz,Manage authentication (login, logout, etc.).)helpr	   )zhf auth loginzhf auth login --token $HF_TOKENz7hf auth login --token $HF_TOKEN --add-to-git-credential)examplesFtokenadd_to_git_credentialzTSave to git credential helper. Useful only if you plan to run git commands directly.returnc                 C   s   t | |d dS )z8Login using a token from huggingface.co/settings/tokens.r   r   N)r	   r    r   T/home/jeff/fluffinator/venv/lib/python3.10/site-packages/huggingface_hub/cli/auth.py
auth_login3   s   r   r
   zhf auth logoutz$hf auth logout --token-name my-token
token_namezName of token to logoutc                 C   s   t | d dS )zLogout from a specific token.r   N)r
   r   r   r   r   auth_logoutH   s   r   c                  C   s   t t  } | std d S td t| dD ]\}}t| d|  q	 z,td}| dkr6W d S t	|d }d|  krHt
| k rOn n| | W S td	 W n tya   td
 Y nw q()Nz+No stored tokens found. Please login first.zAvailable stored tokens:r   z. Tz=Enter the number of the token to switch to (or 'q' to quit): qr   z$Invalid selection. Please try again.z4Invalid input. Please enter a number or 'q' to quit.)listr   keysloggererrorprint	enumerateinputlowerintlen
ValueError)token_namesir   choiceindexr   r   r   _select_token_nameV   s(   

r.   switchzhf auth switchz$hf auth switch --token-name my-tokenzName of the token to switch toc                 C   s6   | du rt  } | du rtd t t| |d dS )zSwitch between access tokens.Nz!No token name provided. Aborting.)r   )r.   r#   typerExitr   )r   r   r   r   r   auth_switch_cmdn   s   r2   r   zhf auth listc                   C   s
   t   dS )zList all stored access tokens.N)r   r   r   r   r   auth_list_cmd   s   
r3   r   zhf auth whoamic                  C   s   t  } | du rtd t t| }ttd|d  dd |d D }|r3ttdd	| td
kr@tdt  dS dS )z;Find out which huggingface.co account you are logged in as.NzNot logged inzuser: namec                 S   s   g | ]}|d  qS )r4   r   ).0orgr   r   r   
<listcomp>   s    zauth_whoami.<locals>.<listcomp>orgszorgs: ,zhttps://huggingface.coz(Authenticated through private endpoint: )	r   r#   r0   r1   r   r   boldjoinr   )r   infor8   r   r   r   auth_whoami   s   r=   )NF)N)r   N)$__doc__typingr   r   r0   huggingface_hub.constantsr   huggingface_hub.hf_apir   _loginr   r   r	   r
   utilsr   r   r   r   
_cli_utilsr   r   
get_logger__name__r!   auth_clicommandboolOptionr   strr   r.   r2   r3   r=   r   r   r   r   <module>   s   

	


