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:
parent
17c8e274dc
commit
9254110b8b
2 changed files with 21 additions and 1 deletions
|
@ -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)."
|
|
@ -44,6 +44,14 @@ options:
|
|||
try to install all of them in this version.
|
||||
type: str
|
||||
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:
|
||||
description:
|
||||
- The state of the Rust package.
|
||||
|
@ -60,6 +68,11 @@ EXAMPLES = r"""
|
|||
community.general.cargo:
|
||||
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
|
||||
community.general.cargo:
|
||||
name: ludusavi
|
||||
|
@ -94,6 +107,7 @@ class Cargo(object):
|
|||
self.path = kwargs["path"]
|
||||
self.state = kwargs["state"]
|
||||
self.version = kwargs["version"]
|
||||
self.locked = kwargs["locked"]
|
||||
|
||||
self.executable = [module.get_bin_path("cargo", True)]
|
||||
|
||||
|
@ -132,6 +146,8 @@ class Cargo(object):
|
|||
def install(self, packages=None):
|
||||
cmd = ["install"]
|
||||
cmd.extend(packages or self.name)
|
||||
if self.locked:
|
||||
cmd.append("--locked")
|
||||
if self.path:
|
||||
cmd.append("--root")
|
||||
cmd.append(self.path)
|
||||
|
@ -164,6 +180,7 @@ def main():
|
|||
path=dict(default=None, type="path"),
|
||||
state=dict(default="present", choices=["present", "absent", "latest"]),
|
||||
version=dict(default=None, type="str"),
|
||||
locked=dict(default=False, type="bool"),
|
||||
)
|
||||
module = AnsibleModule(argument_spec=arg_spec, supports_check_mode=True)
|
||||
|
||||
|
@ -171,6 +188,7 @@ def main():
|
|||
path = module.params["path"]
|
||||
state = module.params["state"]
|
||||
version = module.params["version"]
|
||||
locked = module.params["locked"]
|
||||
|
||||
if not name:
|
||||
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"
|
||||
)
|
||||
|
||||
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
|
||||
installed_packages = cargo.get_installed()
|
||||
if state == "present":
|
||||
|
|
Loading…
Reference in a new issue