From 92dc7cd65c2b5ad9da2a437f8e14415a95b27314 Mon Sep 17 00:00:00 2001 From: Ramunas Dronga Date: Wed, 21 Oct 2015 16:20:53 +0300 Subject: [PATCH] allow specify arguments for composer --- packaging/language/composer.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/packaging/language/composer.py b/packaging/language/composer.py index 1ef93e736fc..fdb84896092 100644 --- a/packaging/language/composer.py +++ b/packaging/language/composer.py @@ -36,6 +36,11 @@ options: - Composer command like "install", "update" and so on required: false default: install + arguments: + description: + - Composer arguments like required package, version and so on + required: false + default: null working_dir: description: - Directory of your project ( see --working-dir ) @@ -102,6 +107,17 @@ notes: EXAMPLES = ''' # Downloads and installs all the libs and dependencies outlined in the /path/to/project/composer.lock - composer: command=install working_dir=/path/to/project + +- composer: + command: "require my/package" + working_dir: "/path/to/project" + +# Clone project and install with all dependencies +- composer: + command: "create-project" + arguments: "package/package /path/to/project ~1.0" + working_dir: "/path/to/project" + prefer_dist: "yes" ''' import os @@ -116,6 +132,8 @@ def parse_out(string): return re.sub("\s+", " ", string).strip() def has_changed(string): + if string == "": + return False return "Nothing to install or update" not in string def get_available_options(module, command='install'): @@ -128,16 +146,17 @@ def get_available_options(module, command='install'): command_help_json = json.loads(out) return command_help_json['definition']['options'] -def composer_command(module, command, options=[]): +def composer_command(module, command, arguments = "", options=[]): php_path = module.get_bin_path("php", True, ["/usr/local/bin"]) composer_path = module.get_bin_path("composer", True, ["/usr/local/bin"]) - cmd = "%s %s %s %s" % (php_path, composer_path, command, " ".join(options)) + cmd = "%s %s %s %s %s" % (php_path, composer_path, command, " ".join(options), arguments) return module.run_command(cmd) def main(): module = AnsibleModule( argument_spec = dict( command = dict(default="install", type="str", required=False), + arguments = dict(default="", type="str", required=False), working_dir = dict(aliases=["working-dir"], required=True), prefer_source = dict(default="no", type="bool", aliases=["prefer-source"]), prefer_dist = dict(default="no", type="bool", aliases=["prefer-dist"]), @@ -152,6 +171,7 @@ def main(): # Get composer command with fallback to default command = module.params['command'] + arguments = module.params['arguments'] available_options = get_available_options(module=module, command=command) options = [] @@ -188,7 +208,7 @@ def main(): if module.check_mode: options.append('--dry-run') - rc, out, err = composer_command(module, command, options) + rc, out, err = composer_command(module, command, arguments, options) if rc != 0: output = parse_out(err)