
    Vh#                     t    d dl mZmZmZ eZdZdZd dlZd dl	m
Z
 d Zd ZddZdd	Zd
 Zedk(  r e        yy)    )absolute_importdivisionprint_functionuy  
module: composer
author:
  - "Dimitrios Tydeas Mengidis (@dmtrs)"
  - "René Moser (@resmo)"
short_description: Dependency Manager for PHP
description:
  - Composer is a tool for dependency management in PHP. It allows you to declare the dependent libraries your project needs
    and it will install them in your project for you.
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  command:
    type: str
    description:
      - Composer command like V(install), V(update) and so on.
    default: install
  arguments:
    type: str
    description:
      - Composer arguments like required package, version and so on.
    default: ''
  executable:
    type: path
    description:
      - Path to PHP executable on the remote host, if PHP is not in E(PATH).
    aliases: [php_path]
  working_dir:
    type: path
    description:
      - Directory of your project (see C(--working-dir)). This is required when the command is not run globally.
      - Will be ignored if O(global_command=true).
  global_command:
    description:
      - Runs the specified command globally.
    type: bool
    default: false
  prefer_source:
    description:
      - Forces installation from package sources when possible (see C(--prefer-source)).
    default: false
    type: bool
  prefer_dist:
    description:
      - Forces installation from package dist even for dev versions (see C(--prefer-dist)).
    default: false
    type: bool
  no_dev:
    description:
      - Disables installation of require-dev packages (see C(--no-dev)).
    default: true
    type: bool
  no_scripts:
    description:
      - Skips the execution of all scripts defined in composer.json (see C(--no-scripts)).
    default: false
    type: bool
  no_plugins:
    description:
      - Disables all plugins (see C(--no-plugins)).
    default: false
    type: bool
  optimize_autoloader:
    description:
      - Optimize autoloader during autoloader dump (see C(--optimize-autoloader)).
      - Convert PSR-0/4 autoloading to classmap to get a faster autoloader.
      - Recommended especially for production, but can take a bit of time to run.
    default: true
    type: bool
  classmap_authoritative:
    description:
      - Autoload classes from classmap only.
      - Implicitly enable optimize_autoloader.
      - Recommended especially for production, but can take a bit of time to run.
    default: false
    type: bool
  apcu_autoloader:
    description:
      - Uses APCu to cache found/not-found classes.
    default: false
    type: bool
  ignore_platform_reqs:
    description:
      - Ignore php, hhvm, lib-* and ext-* requirements and force the installation even if the local machine does not fulfill
        these.
    default: false
    type: bool
  composer_executable:
    type: path
    description:
      - Path to composer executable on the remote host, if composer is not in E(PATH) or a custom composer is needed.
    version_added: 3.2.0
requirements:
  - php
  - composer installed in bin path (recommended C(/usr/local/bin)) or specified in O(composer_executable)
notes:
  - Default options that are always appended in each execution are C(--no-ansi), C(--no-interaction) and C(--no-progress)
    if available.
  - We received reports about issues on macOS if composer was installed by Homebrew. Please use the official install method
    to avoid issues.
a  
- name: Download and installs all libs and dependencies outlined in the /path/to/project/composer.lock
  community.general.composer:
    command: install
    working_dir: /path/to/project

- name: Install a new package
  community.general.composer:
    command: require
    arguments: my/package
    working_dir: /path/to/project

- name: Clone and install a project with all dependencies
  community.general.composer:
    command: create-project
    arguments: package/package /path/to/project ~1.0
    working_dir: /path/to/project
    prefer_dist: true

- name: Install a package globally
  community.general.composer:
    command: require
    global_command: true
    arguments: my/package
N)AnsibleModulec                 L    t        j                  dd|       j                         S )Nz\s+ )resubstrip)strings    n/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/composer.py	parse_outr      s    66&#v&,,..    c                     dD ]  }|| v s y y)N)zNothing to install or updatez$Nothing to install, update or removeFT )r   	no_changes     r   has_changedr      s!    ] 	 r   c                     t        | d|z  d      \  }}}|dk7  rt        |      }| j                  |       | j                  |      }|d   d   S )Nzhelp %sz--no-interaction --format=json)	argumentsr   msg
definitionoptions)composer_commandr   	fail_json	from_json)modulecommandrcouterroutputcommand_help_jsons          r   get_available_optionsr$      s^    #FI,?KklLBS	Qw3V$((-\*955r   c                    |g }| j                   d   }|s#|j                  dd| j                   d   z  g       | j                   d   | j                  dddg      }n| j                   d   }| j                   d	   | j                  d
ddg      }n| j                   d	   }|d|d|rdndd|ddj                  |      d|}| j	                  |      S )Nglobal_commandz--working-dirz'%s'working_dir
executablephpTz/usr/local/bincomposer_executablecomposerr   global )paramsextendget_bin_pathjoinrun_command)r   r   r   r   r&   php_pathcomposer_pathcmds           r   r   r      s    ]]#34N&--2N)NOP}}\"*&&ud5E4FG==.}}*+3++J?O>PQ&;<!)=n(Z\:\^egjgogopwgx  {D  ECc""r   c                     t        t        t        dd      t        dd      t        ddg      t        d      t        d	d
      t        d	d
      t        d	d
      t        dd
      t        d	d
      t        d	d
      t        d	d
      t        dd
      t        d	d
      t        d	d
      t        d            dd	dgfgd      } | j                  d   }t        j                  d|      r| j                  d       | j                  d   }t        | |      }g }g d}|D ]  }||v sd|z  }|j                  |        ddddddddd d!	}|j                         D ]<  \  }}| j                  j                  |      s"||v s'd|z  }|j                  |       > | j                  r,d"|v r|j                  d#       n| j                  dd$|z  %       t        | |||      \  }	}
}|	d&k7  rt        |      }| j                  ||'       y t        |
|z         }| j                  t        |      ||
|z   (       y ))Ninstallstr)defaulttyper-   pathr3   )r:   aliases)r:   FboolT)r   r   r(   r'   r&   prefer_sourceprefer_distno_dev
no_scripts
no_pluginsapcu_autoloaderoptimize_autoloaderclassmap_authoritativeignore_platform_reqsr*   r&   r'   )argument_specrequired_ifsupports_check_moder   z\szBUse the 'arguments' param for passing arguments with the 'command'r   r   )r   r   )zno-ansizno-interactionzno-progressz--%szprefer-sourcezprefer-distzno-devz
no-scriptsz
no-pluginszacpu-autoloaderzoptimize-autoloaderzclassmap-authoritativezignore-platform-reqs)	r>   r?   r@   rA   rB   rC   rD   rE   rF   zdry-runz	--dry-runz2command '%s' does not support check mode, skipping)skippedr   r   )r   stdout)changedr   rK   )r   dictr.   r	   searchr   r$   appenditemsget
check_mode	exit_jsonr   r   r   )r   r   r   available_optionsr   default_optionsoptionoption_paramsparamr   r    r!   r"   s                r   mainrY      sT   72E2*>&)F;u6:U862E7E7 V< $T ?#'F#C!%e&!A $& 1
" '?@ 'F. mmI&G	yy abk*I-VWMGO " #&&f_FNN6"# )$"",4": 6
M ',,. #v==U#2C(Cf_FNN6"#
 ))NN;'T/cfm/mn#FGYHLBS	Qw3VC0 39%V!4&sSr   __main__)r7   )r-   N)
__future__r   r   r   r:   __metaclass__DOCUMENTATIONEXAMPLESr	   ansible.module_utils.basicr   r   r   r$   r   rY   __name__r   r   r   <module>ra      s[    A @iV4 
 4/6#.LT^ zF r   