ideas icon indicating copy to clipboard operation
ideas copied to clipboard

Don't interpret arguments following long switch (`--`) as positional

Open WilliamDEdwards opened this issue 1 year ago • 0 comments

For all WP-CLI commands, arguments following a long switch are interpreted as positional without =:

$ wp user list --role admin
Error: Too many positional arguments: admin

$ wp user list --role=admin
+----+------------+--------------+------------+-----------------+-------+
| ID | user_login | display_name | user_email | user_registered | roles |
+----+------------+--------------+------------+-----------------+-------+
+----+------------+--------------+------------+-----------------+-------+

This is unhandy, but acceptable.

However, it becomes a real usablity issue when calling WP-CLI programmatically.

In my case, Python's subprocess.run is used to call WP-CLI (with shell=False for obvious security reasons).

As a result, I have to do this:

command.append(f"--path={self.path}")

... instead of:

command.extend(["--path", self.path])

This way of working delegates string interpolation - and sometimes even quoting - to the caller, which is not developer-friendly (and probably not very POSIX-y).

WilliamDEdwards avatar Jun 25 '24 10:06 WilliamDEdwards