U
    ”Ê¹j¾  ã                   @   s|   d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ e e¡ZG d	d
„ d
ƒZG dd„ de	ƒZdS )a©  Contains command to update or delete files in a repository using the CLI.

Usage:
    # delete all
    huggingface-cli repo-files <repo_id> delete "*"

    # delete single file
    huggingface-cli repo-files <repo_id> delete file.txt

    # delete single folder
    huggingface-cli repo-files <repo_id> delete folder/

    # delete multiple
    huggingface-cli repo-files <repo_id> delete file.txt folder/ file2.txt

    # delete multiple patterns
    huggingface-cli repo-files <repo_id> delete file.txt "*.json" "folder/*.parquet"

    # delete from different revision / repo-type
    huggingface-cli repo-files <repo_id> delete file.txt --revision=refs/pr/1 --repo-type=dataset
é    )Ú_SubParsersAction)ÚListÚOptional)Úlogging)ÚBaseHuggingfaceCLICommand)ÚHfApié   )Úshow_deprecation_warningc                   @   s(   e Zd Zddœdd„Zddœdd„ZdS )ÚDeleteFilesSubCommandN)Úreturnc                 C   sZ   || _ |j| _|j| _|j| _t|jdd�| _|j| _|j| _|j	| _	|j
| _
|j| _d S )Nzhuggingface-cli)ÚtokenZlibrary_name)ÚargsÚrepo_idÚ	repo_typeÚrevisionr   r   ÚapiÚpatternsÚcommit_messageÚcommit_descriptionÚ	create_pr)Úselfr   © r   úb/var/www/html/bwave/python/venv/lib/python3.8/site-packages/huggingface_hub/commands/repo_files.pyÚ__init__3   s    zDeleteFilesSubCommand.__init__c              	   C   sV   t ddƒ t ¡  | jj| j| j| j| j| j	| j
| jd�}td|› d�ƒ t ¡  d S )Nzhuggingface-cli repo-fileszhf repo-files)Zdelete_patternsr   r   r   r   r   r   z+Files correctly deleted from repo. Commit: Ú.)r	   r   Zset_verbosity_infor   Zdelete_filesr   r   r   r   r   r   r   ÚprintZset_verbosity_warning)r   Úurlr   r   r   Úrun?   s    
ù	zDeleteFilesSubCommand.run)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r
   2   s   r
   c                   @   s   e Zd Zeedœdd„ƒZdS )ÚRepoFilesCommand)Úparserc                 C   sÔ   | j ddd�}|jdtdd� |jddd	�}|j d
dd�}|jdd„ d� |jddtdd� |jddddgddd� |jdtdd� |jdtdd� |jdtdd� |jdd d!d"� |jd#td$d� |jtd� d S )%Nz
repo-filesz!Manage files in a repo on the Hub)Úhelpr   z9The ID of the repo to manage (e.g. `username/repo-name`).)Útyper#   z$Action to execute against the files.T)r#   ÚrequiredÚdeletez#Delete files from a repo on the Hubc                 S   s   t | ƒS )N)r
   )r   r   r   r   Ú<lambda>_   ó    z6RepoFilesCommand.register_subcommand.<locals>.<lambda>)Úfuncr   ú+z'Glob patterns to match files to delete.)Únargsr$   r#   z--repo-typeÚmodelZdatasetÚspacez/Type of the repo to upload to (e.g. `dataset`).)ÚchoicesÚdefaultr#   z
--revisionz°An optional Git revision to push to. It can be a branch name or a PR reference. If revision does not exist and `--create-pr` is not set, a branch will be automatically created.z--commit-messagez9The summary / title / first line of the generated commit.z--commit-descriptionz(The description of the generated commit.z--create-prÚ
store_truez7Whether to create a new Pull Request for these changes.)Úactionr#   z--tokenzIA User Access Token generated from https://huggingface.co/settings/tokens)Ú
add_parserÚadd_argumentÚstrÚadd_subparsersÚset_defaultsr!   )r"   Zrepo_files_parserZrepo_files_subparsersZdelete_subparserr   r   r   Úregister_subcommandQ   sj      ÿþþüüü	  ÿ  ÿ  ÿýz$RepoFilesCommand.register_subcommandN)r   r   r    Ústaticmethodr   r7   r   r   r   r   r!   P   s   r!   N)Ú__doc__Úargparser   Útypingr   r   Zhuggingface_hubr   Zhuggingface_hub.commandsr   Zhuggingface_hub.hf_apir   Z
_cli_utilsr	   Z
get_loggerr   Úloggerr
   r!   r   r   r   r   Ú<module>   s   
