Skip to content

Commit

Permalink
[PR #7405/f7267c71 backport][stable-7] Fix the ability to run Compose…
Browse files Browse the repository at this point in the history
…r "working_dir" dependent commands (#7460)

Fix the ability to run Composer "working_dir" dependent commands (#7405)

* pass the working_dir to all composer command invocations that are not global

* add changelog fragment

* Update changelog fragment

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit f7267c7)

Co-authored-by: Xavier Lacot <xavier@lacot.org>
  • Loading branch information
patchback[bot] and xavierlacot authored Nov 1, 2023
1 parent b2eb0fb commit be2fd43
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/3787-pass-composer-working-dir.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- composer - fix impossible to run ``working_dir`` dependent commands. The module was throwing an error when trying to run a ``working_dir`` dependent command, because it tried to get the command help without passing the ``working_dir`` (https://github.com/ansible-collections/community.general/issues/3787).
13 changes: 7 additions & 6 deletions plugins/modules/composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,15 @@ def get_available_options(module, command='install'):
return command_help_json['definition']['options']


def composer_command(module, command, arguments="", options=None, global_command=False):
def composer_command(module, command, arguments="", options=None):
if options is None:
options = []

global_command = module.params['global_command']

if not global_command:
options.extend(['--working-dir', "'%s'" % module.params['working_dir']])

if module.params['executable'] is None:
php_path = module.get_bin_path("php", True, ["/usr/local/bin"])
else:
Expand Down Expand Up @@ -217,7 +222,6 @@ def main():
module.fail_json(msg="Use the 'arguments' param for passing arguments with the 'command'")

arguments = module.params['arguments']
global_command = module.params['global_command']
available_options = get_available_options(module=module, command=command)

options = []
Expand All @@ -234,9 +238,6 @@ def main():
option = "--%s" % option
options.append(option)

if not global_command:
options.extend(['--working-dir', "'%s'" % module.params['working_dir']])

option_params = {
'prefer_source': 'prefer-source',
'prefer_dist': 'prefer-dist',
Expand All @@ -260,7 +261,7 @@ def main():
else:
module.exit_json(skipped=True, msg="command '%s' does not support check mode, skipping" % command)

rc, out, err = composer_command(module, command, arguments, options, global_command)
rc, out, err = composer_command(module, command, arguments, options)

if rc != 0:
output = parse_out(err)
Expand Down

0 comments on commit be2fd43

Please sign in to comment.