Skip to content

Add shell array parsing helper#4623

Merged
gitlost merged 6 commits intomasterfrom
4616-parse-shell-arrays
Jan 19, 2018
Merged

Add shell array parsing helper#4623
gitlost merged 6 commits intomasterfrom
4616-parse-shell-arrays

Conversation

@schlessera
Copy link
Member

Adds two helper functions:

  • WP_CLI\Utils\parse_shell_arrays( $assoc_args, $array_arguments )
    This takes an existing $assoc_args array, and parses possible shell arguments for all keys that are provided in $array_arguments

  • WP_CLI\Utils\is_json( $argument, $ignore_scalars = true )
    Helper function for the above parsing, that detects whether a given string is valid JSON.

See #4616

* @return bool Whether the provided string is a valid JSON representation.
*/
function is_json( $argument, $ignore_scalars = true ) {
if ( empty( $argument ) || ! is_string( $argument ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be picky this should be if ( ! is_string( $argument ) || 0 === strlen( $argument ) ) { to deal with if given '0'.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Picky is good. Why did you merge anyway?

I'll add a bug report as a good first issue.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #4629

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, I merged because we've so many bugs, PRs and other stuff outstanding and release is 8 days from now!

@gitlost gitlost merged commit 7dcffc2 into master Jan 19, 2018
@gitlost gitlost deleted the 4616-parse-shell-arrays branch January 19, 2018 17:08
@gitlost
Copy link
Contributor

gitlost commented Jan 25, 2018

Removing this from the 1.5.0 milestone in favor of #4638

Edit: doh, meant to do it to #4616

@gitlost gitlost modified the milestone: 1.5.0 Jan 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants