1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

[PR #6134/a0d8f4de backport][stable-7] feat(cargo): add locked option (#7310)

feat(cargo): add locked option (#6134)

* feat(cargo): add locked option

This commit introduces locked option to cargo module,
allowing user to install with locked dependency.

Equivalent to `--locked` flag of `cargo install` command

* Update docs.

---------

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

Co-authored-by: Murad Bashirov <66242799+m-spitfire@users.noreply.github.com>
This commit is contained in:
patchback[bot] 2023-09-25 05:51:31 +02:00 committed by GitHub
parent 17c8e274dc
commit 9254110b8b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- "cargo - add option ``locked`` which allows user to specify install the locked version of dependency instead of latest compatible version (https://github.com/ansible-collections/community.general/pull/6134)."

View file

@ -44,6 +44,14 @@ options:
try to install all of them in this version. try to install all of them in this version.
type: str type: str
required: false required: false
locked:
description:
- Install with locked dependencies.
- This is only used when installing packages.
required: false
type: bool
default: false
version_added: 7.5.0
state: state:
description: description:
- The state of the Rust package. - The state of the Rust package.
@ -60,6 +68,11 @@ EXAMPLES = r"""
community.general.cargo: community.general.cargo:
name: ludusavi name: ludusavi
- name: Install "ludusavi" Rust package with locked dependencies
community.general.cargo:
name: ludusavi
locked: true
- name: Install "ludusavi" Rust package in version 0.10.0 - name: Install "ludusavi" Rust package in version 0.10.0
community.general.cargo: community.general.cargo:
name: ludusavi name: ludusavi
@ -94,6 +107,7 @@ class Cargo(object):
self.path = kwargs["path"] self.path = kwargs["path"]
self.state = kwargs["state"] self.state = kwargs["state"]
self.version = kwargs["version"] self.version = kwargs["version"]
self.locked = kwargs["locked"]
self.executable = [module.get_bin_path("cargo", True)] self.executable = [module.get_bin_path("cargo", True)]
@ -132,6 +146,8 @@ class Cargo(object):
def install(self, packages=None): def install(self, packages=None):
cmd = ["install"] cmd = ["install"]
cmd.extend(packages or self.name) cmd.extend(packages or self.name)
if self.locked:
cmd.append("--locked")
if self.path: if self.path:
cmd.append("--root") cmd.append("--root")
cmd.append(self.path) cmd.append(self.path)
@ -164,6 +180,7 @@ def main():
path=dict(default=None, type="path"), path=dict(default=None, type="path"),
state=dict(default="present", choices=["present", "absent", "latest"]), state=dict(default="present", choices=["present", "absent", "latest"]),
version=dict(default=None, type="str"), version=dict(default=None, type="str"),
locked=dict(default=False, type="bool"),
) )
module = AnsibleModule(argument_spec=arg_spec, supports_check_mode=True) module = AnsibleModule(argument_spec=arg_spec, supports_check_mode=True)
@ -171,6 +188,7 @@ def main():
path = module.params["path"] path = module.params["path"]
state = module.params["state"] state = module.params["state"]
version = module.params["version"] version = module.params["version"]
locked = module.params["locked"]
if not name: if not name:
module.fail_json(msg="Package name must be specified") module.fail_json(msg="Package name must be specified")
@ -180,7 +198,7 @@ def main():
LANG="C", LC_ALL="C", LC_MESSAGES="C", LC_CTYPE="C" LANG="C", LC_ALL="C", LC_MESSAGES="C", LC_CTYPE="C"
) )
cargo = Cargo(module, name=name, path=path, state=state, version=version) cargo = Cargo(module, name=name, path=path, state=state, version=version, locked=locked)
changed, out, err = False, None, None changed, out, err = False, None, None
installed_packages = cargo.get_installed() installed_packages = cargo.get_installed()
if state == "present": if state == "present":