Skip to content

Reinvestigate command-line input of associative arrays #4616

@schlessera

Description

@schlessera

WP-CLI includes some arguments that need an associative array as input (like wp post create --meta_input), but it does not support any way of entering these on the command line.

A previous issue on this was closed in favor of handling CRUD operations through the WP REST API, however this is far from reliable/complete and we will not switch to using that method as a new default anytime soon.

This is why I want to reevaluate how we could process shell input to accept associative (and maybe even nested) arrays.

My current thought is to have a utility function to pass all these arguments through, like WP_CLI\Utils\parse_array(), which would try to parse the provided input as either JSON array syntax (["foo":"bar"]) or PHP array syntax (["foo"=>"bar"]). Whatever arguments need (associative/nested) arrays would run their value through this function, and in case it returns false, through an error that the argument could not be parsed/is not a valid array.

We'll probably detect lots of edge cases over time. Having this parsing in one central location makes bug fixes across all commands easy.

Related: #1323

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions