o
    wiE                     @   s   d Z ddlZddlZddlmZmZmZ ddlmZ ddl	m
Z
 dejdefd	d
ZdejddfddZdejdefddZdejdefddZdejfddZdejdefddZddeee  defddZdS )ac  
CLI parsing for :command:`pysemver` command.

Each command in :command:`pysemver` is mapped to a ``cmd_`` function.
The :func:`main <semver.cli.main>` function calls
:func:`createparser <semver.cli.createparser>` and
:func:`process <semver.cli.process>` to parse and process
all the commandline options.

The result of each command is printed on stdout.
    N)castListOptional   )Version)__version__argsreturnc                 C   sV   dddddd}| j du r| jdd	g t| j}t||tt| j  }t| S )
z
    Subcommand: Bumps a version.

    Synopsis: bump <PART> <VERSION>
    <PART> can be major, minor, patch, prerelease, or build

    :param args: The parsed arguments
    :return: the new, bumped version
    
bump_major
bump_minor
bump_patchbump_prerelease
bump_build)majorminorpatch
prereleasebuildNbumpz-h)	r   parser
parse_argsr   parseversiongetattrr   str)r   maptableverfunc r   G/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/semver/cli.pycmd_bump   s   

r    c                 C   s   t | jrdS td| j )z
    Subcommand: Checks if a string is a valid semver version.

    Synopsis: check <VERSION>

    :param args: The parsed arguments
    NzInvalid version %r)r   is_validr   
ValueErrorr   r   r   r   	cmd_check1   s   r$   c                 C      t | j}t|| jS )z
    Subcommand: Compare two versions.

    Synopsis: compare <VERSION1> <VERSION2>

    :param args: The parsed arguments
    )r   r   version1r   compareversion2)r   ver1r   r   r   cmd_compare>      r*   c                 C   r%   )z
    Subcommand: Determines the next version, taking prereleases into account.

    Synopsis: nextver <VERSION> <PART>

    :param args: The parsed arguments
    )r   r   r   r   next_versionpart)r   r   r   r   r   cmd_nextverJ   r+   r.   c                  C   s>  t jttd} | jdddt d |  }|jddd}|jt	d	 |jd
dd |jddd |jddd}|jt
d	 |jddd}|jddd|jddd|jddd|jddd|jdddfD ]	}|jddd qd|jddd}|jtd	 |jddd |jd d!d}|jtd	 |jddd |jd"d#d | S )$z\
    Create an :class:`argparse.ArgumentParser` instance.

    :return: parser instance
    )progdescriptionz	--versionr   z	%(prog)s )actionr   r'   zCompare two versions)help)r   r&   zFirst versionr(   zSecond versionr   zBumps a versionzBump commands)titledestr   z"Bump the major part of the versionr   z"Bump the minor part of the versionr   z"Bump the patch part of the versionr   z'Bump the prerelease part of the versionr   z"Bump the build part of the versionzVersion to raisecheckz,Checks if a string is a valid semver versionzVersion to checknextverz=Determines the next version, taking prereleases into account.r-   z1One of 'major', 'minor', 'patch', or 'prerelease')argparseArgumentParser__package____doc__add_argumentr   add_subparsers
add_parserset_defaultsr*   r    r$   r.   )r   sparser_compareparser_bumpsbpparser_checkparser_nextverr   r   r   createparserV   sB   
rF   c                 C   s$   t | ds| j  t | | S )z
    Process the input from the CLI.

    :param args: The parsed arguments
    :param parser: the parser instance
    :return: result of the selected action
    r   )hasattrr   
print_help
SystemExitr   r#   r   r   r   process   s   


rJ   cliargsc              
   C   sr   zt  }|j| d}||_t|}|durt| W dS  ttfy8 } ztd|tjd W Y d}~dS d}~ww )z
    Entry point for the application script.

    :param list cliargs: Arguments to parse or None (=use :class:`sys.argv`)
    :return: error code
    r#   Nr   ERROR)file   )	rF   r   r   rJ   printr"   	TypeErrorsysstderr)rK   r   r   resulterrr   r   r   main   s   rU   )N)r:   r7   rQ   typingr   r   r   r   r   	__about__r   	Namespacer   r    r$   r*   r.   r8   rF   rJ   intrU   r   r   r   r   <module>   s    5 