o
    i                     @   s  d Z ddlZddlZddlZddlmZ ddlmZ ddlZddl	m
Z
 ddlmZ ddlmZ dd	lmZ eeZd
edB fddZd
efddZddddddddededB dedee dB dee dB deeef dB dedB dedB dedB d
efddZddddddddddedeedB ejddgd d!f deee dB ejd"d#d$d%f deee dB ejd&d'd$d%f deee dB ejd(d)d$d%f d*eedB ejd+d,d-f d.eedB ejd/d0d-f deedB ejd1d2d-f deedB ejd3d4d-f d
dfd5d6ZdS )7z:Gemini CLI integration for FastMCP install using Cyclopts.    N)Path)	Annotated)print)
get_logger)UVEnvironment   )process_common_argsreturnc               
   C   s   t d} | r!ztj| dgddd | W S  tjtfy    Y nw t d d d tdt d d	 d td
g}|D ]&}| rcztjt	|dgddd t	|W   S  tjtfyb   Y q=w q=dS )zFind the Gemini CLI command.geminiz	--versionT)checkcapture_outputz.geminilocalz/usr/local/bin/geminiz.npm-globalbinz/opt/homebrew/bin/geminiN)
shutilwhich
subprocessrunCalledProcessErrorFileNotFoundErrorr   homeexistsstr)gemini_in_pathpotential_pathspath r   d/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/fastmcp/cli/install/gemini_cli.pyfind_gemini_command   s>   

r   c                   C   s
   t  duS )z!Check if Gemini CLI is available.N)r   r   r   r   r   check_gemini_cli_available@   s   
r   )with_editablewith_packagesenv_varspython_versionwith_requirementsprojectfileserver_objectnamer   r    r!   r"   r#   r$   c             
   C   sj  t  }	|	std dS t||pg dg |||d}
|r%|   d| }nt|  }|
dd|g}|	ddg}|rO| D ]\}}|d	| d
| g q>|||d dg ||dd  ztj	|dddd W dS  tj
y } ztd| d|jr|j nt| d W Y d}~dS d}~w ty } ztd| d| d W Y d}~dS d}~ww )a  Install FastMCP server in Gemini CLI.

    Args:
        file: Path to the server file
        server_object: Optional server object name (for :object suffix)
        name: Name for the server in Gemini CLI
        with_editable: Optional list of directories to install in editable mode
        with_packages: Optional list of additional packages to install
        env_vars: Optional dictionary of environment variables
        python_version: Optional Python version to use
        with_requirements: Optional requirements file to install from
        project: Optional project directory to run within

    Returns:
        True if installation was successful, False otherwise
    z[red]Gemini CLI not found.[/red]
[blue]Please ensure Gemini CLI is installed. Try running 'gemini --version' to verify.[/blue]
[blue]You can install it using 'npm install -g @google/gemini-cli'.[/blue]
Ffastmcp)pythondependenciesrequirementsr$   editable:r   mcpaddz-e=r   z--r   NT)r   r   textz[red]Failed to install '[bold]z[/bold]' in Gemini CLI: z[/red])r   r   r   resolver   build_commanditemsextendr   r   r   stderrstrip	Exception)r%   r&   r'   r   r    r!   r"   r#   r$   
gemini_cmd
env_configserver_specfull_command	cmd_partskeyvalueer   r   r   install_gemini_cliE   sJ   	
$rA   )server_namer   r    r!   env_filer)   r#   r$   r;   rB   z--namez-nz(Custom name for the server in Gemini CLI)r'   helpz--with-editablezVDirectory with pyproject.toml to install in editable mode (can be used multiple times) )rD   negativez--withz;Additional packages to install (can be used multiple times)z--envzFEnvironment variables in KEY=VALUE format (can be used multiple times)rC   z
--env-filez)Load environment variables from .env file)rD   r)   z--pythonz(Python version to use (e.g., 3.10, 3.11)z--with-requirementsz.Requirements file to install dependencies fromz	--projectz2Run the command within the given project directoryc                   sz   |pg }|pg }|pg }t | ||||I dH \}	}
}}}t|	|
|||||||d	}|r6td| d dS td dS )zInstall an MCP server in Gemini CLI.

    Args:
        server_spec: Python file to install, optionally with :object suffix
    N)	r%   r&   r'   r   r    r!   r"   r#   r$   z[green]Successfully installed 'z' in Gemini CLIr   )r   rA   r   sysexit)r;   rB   r   r    r!   rC   r)   r#   r$   r%   r&   r'   packagesenv_dictsuccessr   r   r   gemini_cli_command   s*   E
rL   )__doc__r   r   rG   pathlibr   typingr   cycloptsrichr   fastmcp.utilities.loggingr   6fastmcp.utilities.mcp_server_config.v1.environments.uvr   sharedr   __name__loggerr   r   boolr   listdictrA   	ParameterrL   r   r   r   r   <module>   s   ,


	

Z



")07>