New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add `post exists` command #182

Merged
merged 11 commits into from Dec 12, 2018

Conversation

3 participants
@BhargavBhandari90
Copy link
Contributor

BhargavBhandari90 commented May 2, 2018

For #180

Bhargav added some commits May 2, 2018

Bhargav
Bhargav

@BhargavBhandari90 BhargavBhandari90 changed the title WIP: Add command for post exists Add command for post exists May 2, 2018

@BhargavBhandari90 BhargavBhandari90 changed the title Add command for post exists WIP: Add command for post exists May 2, 2018

@BhargavBhandari90 BhargavBhandari90 changed the title WIP: Add command for post exists Add command for post exists May 5, 2018

@schlessera
Copy link
Member

schlessera left a comment

The command as it is now cannot easily be used for scripting purposes.

For a command like this, which is meant to run a check for use in conditionals, you should model it after https://github.com/wp-cli/wp-cli/blob/master/php/commands/src/CLI_Command.php#L623, producing a shell exit code of 0 for success, and 1 for failure.

This way, one can use the command within shell script conditionals:

if wp post exists 42; then
   echo "Skipping post creation, it already exists."
fi
@schlessera

This comment has been minimized.

Copy link
Member

schlessera commented May 8, 2018

I see that you modeled this after wp comment exists. That one is also not easily usable through scripting. I think it should be changed as well.

For BC reasons, you could print a WP_CLI::success() message for success (which produces an exit code of 0) or WP_CLI::halt() on failure with an exit code of 1.

@schlessera

This comment has been minimized.

Copy link
Member

schlessera commented Jul 3, 2018

@BhargavBhandari90 Are you still up for working on this? Do you need help with something?

Bhargav added some commits Aug 11, 2018

@BhargavBhandari90

This comment has been minimized.

Copy link
Contributor

BhargavBhandari90 commented Aug 11, 2018

Hi @schlessera,

Please check my latest commit. Is this what you wanted? If yes then I will modify comment command and feature tests.

Sorry for the delay.

* $ echo $?
* 0
*
* # The post is not exists.

This comment has been minimized.

@swissspidy

swissspidy Aug 13, 2018

Contributor

Correct would be:

The post does not exist.

This comment has been minimized.

@BhargavBhandari90

BhargavBhandari90 Aug 14, 2018

Contributor

oops!!!! Thanks @swissspidy

Bhargav added some commits Aug 14, 2018

Bhargav
Bhargav
Show resolved Hide resolved features/post.feature
"""
And the return code should be 0

When I run `wp post exists 1000`

This comment has been minimized.

@schlessera

schlessera Aug 20, 2018

Member

As you expect this call to return an error (non-null exit code), you need to use When I try..., not When I run...

Bhargav
@BhargavBhandari90

This comment has been minimized.

Copy link
Contributor

BhargavBhandari90 commented Oct 20, 2018

@schlessera Requested changes are done. Sorry for being so late.

schlessera added some commits Dec 12, 2018

@schlessera schlessera added this to the 2.0.2 milestone Dec 12, 2018

@schlessera schlessera merged commit 26ce047 into wp-cli:master Dec 12, 2018

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@schlessera schlessera changed the title Add command for post exists Add `post exists` command Dec 12, 2018

@schlessera

This comment has been minimized.

Copy link
Member

schlessera commented Dec 12, 2018

Thanks for the pull request, @BhargavBhandari90 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment