Repository: ansible-collections/community.general

Issue:
Using withbdeps: false with the portage module causes the task to fail
### Summary

Using `withbdeps: false` with the `portage` module causes the task to fail.

### Issue Type

Bug Report

### Component Name

portage

### Ansible Version

```console
ansible [core 2.14.3]
  config file = /home/dharding/.config/ansible.cfg
  configured module search path = ['/home/dharding/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.11/site-packages/ansible
  ansible collection location = /home/dharding/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/lib/python-exec/python3.11/ansible
  python version = 3.11.2 (main, Mar 16 2023, 10:40:25) [GCC 12.2.1 20230121] (/usr/bin/python3.11)
  jinja version = 3.1.2
  libyaml = True
```

### Community.general Version

```console
$ ansible-galaxy collection list community.general

# /usr/lib/python3.11/site-packages/ansible_collections
Collection        Version
----------------- -------
community.general 6.4.0
```

### Configuration

```console
$ ansible-config dump --only-changed
CONFIG_FILE() = /home/[redacted]/.config/ansible.cfg
DEFAULT_VAULT_PASSWORD_FILE(env: ANSIBLE_VAULT_PASSWORD_FILE) = /home/[redacted]/.local/bin/get_ansible_vault_pass
INTERPRETER_PYTHON(/home/[redacted]/.config/ansible.cfg) = /usr/bin/python3
RETRY_FILES_ENABLED(/home/[redacted]/.config/ansible.cfg) = False
```

### OS / Environment

Target OS:  Gentoo Linux

### Steps to Reproduce

```yaml
- hosts: *
  become: true
  tasks:
    - portage:
        name: "@world"
        withbdeps: false
```

### Expected Results

The task would complete successfully.

### Actual Results

The task fails due to emerge failing with the following error message:

```console
emerge: error: argument --with-bdeps: expected one argument
```

### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct


Discussion:
Files identified in the description:
* [`plugins/modules/portage.py`](https://github.com/ansible-collections/community.general/blob/main/plugins/modules/portage.py)

If these files are incorrect, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/devel/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @Tatsh @wltjr
[click here for bot help](https://github.com/ansible/ansibullbot/blob/devel/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/plugins/modules/portage.py b/plugins/modules/portage.py
--- a/plugins/modules/portage.py
+++ b/plugins/modules/portage.py
@@ -383,14 +383,12 @@ def emerge_packages(module, packages):
             """Fallback to default: don't use this argument at all."""
             continue
 
-        if not flag_val:
-            """If the value is 0 or 0.0: add the flag, but not the value."""
-            args.append(arg)
-            continue
-
         """Add the --flag=value pair."""
-        if isinstance(p[flag], bool):
+        if isinstance(flag_val, bool):
             args.extend((arg, to_native('y' if flag_val else 'n')))
+        elif not flag_val:
+            """If the value is 0 or 0.0: add the flag, but not the value."""
+            args.append(arg)
         else:
             args.extend((arg, to_native(flag_val)))
 


Test patch: