o
    i                     @   s   d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	m
Z
 ddlmZ ddlmZ ddlmZ dd	lmZ d
d ZeedZejeddd	ddddddedeedB ededf dee	dB ededf dedef
ddZdS )z1Generate documentation for Cyclopts applications.    )Path)	Annotated)app)FORMAT_ALIASES	DocFormatnormalize_format)Group)load_app_from_script)	Parameter)UNSETc              	   C   s   |  d}|  d}|jtu re|jtu rtd|jr!t|jds%td|jj }|s1td|d}|s<tdt |}|d u r`d	d
 t	 D }td| dd
tt| d||_d S d S )Nz--formatz--outputz>"--format" must be specified when output path is not provided.suffixzB"--output" must be a valid file path when format is not specified.zOutput file must have an extension to infer format (e.g., .md, .html, .rst). Please specify "--format" explicitly or add an extension to the output file..zwInvalid file extension. Output file must have a valid extension after the period. Please specify "--format" explicitly.c                 S   s"   g | ]}t |d krd| qS )   r   )len).0ext r   W/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/cyclopts/cli/docs.py
<listcomp>1   s   " z+_format_group_validator.<locals>.<listcomp>z+Cannot infer format from output extension "z". Supported extensions: z, z'. Please specify "--format" explicitly.)getvaluer   
ValueErrorhasattrr   lowerlstripr   keysjoinsortedset)argument_collection
format_arg
output_argr   
suffix_keyinferred_formatsupported_extensionsr   r   r   _format_group_validator   s6   






r%   )	validator )negative)default_parameterNF   )formatinclude_hiddenheading_levelscriptoutputz-o)aliasgroupr+   z-fr,   r-   c                C   sR   |du rt dt|}t| \}}|j|||d}|r#|| dS t| dS )a  Generate documentation for a Cyclopts application.

    Parameters
    ----------
    script : str
        Python script path, optionally with ``':app_object'`` notation to specify
        the App object. If not specified, will search for App objects in the
        script's global namespace.
    output : Optional[Path]
        Output file path. If not specified, prints to stdout.
    format : Optional[DocFormat]
        Output format for documentation. If not specified, inferred from output
        file extension.
    include_hidden : bool
        Include hidden commands in documentation.
    heading_level : int
        Starting heading level for markdown format.
    NzMust specify format.)output_formatr,   r-   )r   r   r	   generate_docs
write_textprint)r.   r/   r+   r,   r-   app_obj_docs_contentr   r   r   r3   >   s   r3   )N)__doc__pathlibr   typingr   cyclopts.clir   cyclopts.docs.typesr   r   r   cyclopts.groupr   cyclopts.loaderr	   cyclopts.parameterr
   cyclopts.utilsr   r%   format_groupcommandstrboolintr3   r   r   r   r   <module>   s@    
)
	