Cannot set operation argument as list from CLI

Open Beginner friendly
#1,869 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
python
Domain
cli

Research direction

Start by reproducing the listed server.user CLI commands and tracing the CLI operation-argument parsing. Verify that a list-valued groups argument reaches server.user as a list of strings rather than characters, while ordinary string arguments remain unchanged.

Written by the indexing model from the issue text.

Description

bug facts operations

Describe the bug

The operation server.user accepts an argument groups which needs to be a list of strings.
There is no way to define a list when calling this operation from the CLI - it always ends up as list of single characters.

To Reproduce

This all does not work:

pyinfra INVENTORY.py server.user user=abc groups=[group1]
pyinfra INVENTORY.py server.user user=abc groups=["group1"]
pyinfra INVENTORY.py server.user user=abc 'groups=[group1]'
pyinfra INVENTORY.py server.user user=abc groups='["group1"]'
pyinfra INVENTORY.py server.user user=abc 'groups=["group1"]'

because the CLI does not interpret the arguments.

Expected behavior

It should be possible to set arguments which require lists.
Just changing kwargs[key] = value to e.g.

try:
    kwargs[key] = ast.literal_eval(value)
except (SyntaxError, ValueError):
    kwargs[key] = value

should be sufficient.

Meta

pyinfra v3.9.2
Other facts are not relevant.

Dominant language
Python
Stars
6k
Forks
548
Avg merge
7d 17h
Merged PRs (30d)
13

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from pyinfra-dev/pyinfra

All issues in pyinfra-dev/pyinfra

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.