cargo: add support for --features flag (#10198)

* feat(cargo): add --features flag to cargo module so it activates through install

* docs(cargo): 10198 cargo features parameter changelog

* docs: fix wrong pull request number in yml file

* docs: match default [] to be the same in docs and specs

* docs: bump version_added from 10.8.0 to 11.0.0

* style(example): change from json sequence syntax to yaml list
This commit is contained in:
Konrad Konieczny 2025-06-15 12:27:14 +02:00 committed by GitHub
parent 1956815884
commit 497fcd350f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 0 deletions

View file

@ -68,6 +68,15 @@ options:
type: path
required: false
version_added: 9.1.0
features:
description:
- List of features to activate.
- This is only used when installing packages.
type: list
elements: str
required: false
default: []
version_added: 11.0.0
requirements:
- cargo installed
"""
@ -106,6 +115,12 @@ EXAMPLES = r"""
community.general.cargo:
name: ludusavi
directory: /path/to/ludusavi/source
- name: Install "serpl" Rust package with ast_grep feature
community.general.cargo:
name: serpl
features:
- ast_grep
"""
import json
@ -125,6 +140,7 @@ class Cargo(object):
self.version = kwargs["version"]
self.locked = kwargs["locked"]
self.directory = kwargs["directory"]
self.features = kwargs["features"]
@property
def path(self):
@ -176,6 +192,8 @@ class Cargo(object):
if self.directory:
cmd.append("--path")
cmd.append(self.directory)
if self.features:
cmd += ["--features", ",".join(self.features)]
return self._exec(cmd)
def is_outdated(self, name):
@ -236,6 +254,7 @@ def main():
version=dict(default=None, type="str"),
locked=dict(default=False, type="bool"),
directory=dict(default=None, type="path"),
features=dict(default=[], required=False, type="list", elements="str"),
)
module = AnsibleModule(argument_spec=arg_spec, supports_check_mode=True)