Skip to content
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 --headers parameter #58

Merged
merged 2 commits into from Jul 31, 2018

Conversation

3 participants
@greatislander
Copy link
Contributor

greatislander commented Jul 26, 2018

This PR resolves #47 by adding a --headers parameter which accepts a JSON-formatted array of custom header values which are added to the POT file. If custom headers are passed which correspond to defaults, the default values will be replaced.

@swissspidy swissspidy changed the title Add --headers parameter (fix #47) Add --headers parameter Jul 26, 2018

@@ -163,6 +171,10 @@ public function __invoke( $args, $assoc_args ) {
$this->exclude = array_unique( $this->exclude );
}
if ( isset( $assoc_args['headers'] ) ) {
$this->headers = json_decode( $assoc_args['headers'], true );

This comment has been minimized.

@swissspidy

swissspidy Jul 26, 2018

Member

WP-CLI has a nice little utility method for this so you don't need isset() and json_decode().

Example:

$array_arguments = array( 'headers' );
$assoc_args      = \WP_CLI\Utils\parse_shell_arrays( $assoc_args, $array_arguments );
When I run `wp i18n make-pot wp-content/plugins/hello-world wp-content/plugins/hello-world/languages/hello-world.pot --headers='{"Report-Msgid-Bugs-To":"https://github.com/hello-world/hello-world/"}'`
And the wp-content/plugins/hello-world/languages/hello-world.pot file should contain:
"""
"Report-Msgid-Bugs-To: https://github.com/hello-world/hello-world/\n"

This comment has been minimized.

@swissspidy

swissspidy Jul 26, 2018

Member

I would add another test like

And the wp-content/plugins/hello-world/languages/hello-world.pot file should not contain:
  """
  "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/hello-world\n"
  """

to prove that the heaader is indeed being replaced and not added.

$this->skip_js = Utils\get_flag_value( $assoc_args, 'skip-js', $this->skip_js );
$this->source = realpath( $args[0] );
$this->slug = Utils\get_flag_value( $assoc_args, 'slug', Utils\basename( $this->source ) );
$this->skip_js = Utils\get_flag_value( $assoc_args, 'skip-js', $this->skip_js );

This comment has been minimized.

@swissspidy

swissspidy Jul 26, 2018

Member

Unintended whitespace changes I guess? :-)

@swissspidy

This comment has been minimized.

Copy link
Member

swissspidy commented Jul 26, 2018

Thanks @greatislander! This is coming along nicely.

Adjustments based on code review
- Use WP-CLI utility functions where possible
- Fix inadvertent whitespace changes
- Revert accidental composer.json changes
@greatislander

This comment has been minimized.

Copy link
Contributor Author

greatislander commented Jul 26, 2018

@swissspidy Updated based on your feedback -- let me know if there's any other changes you'd like!

@swissspidy swissspidy requested review from schlessera and swissspidy Jul 28, 2018

@schlessera schlessera added this to the 0.1.0 milestone Jul 31, 2018

@schlessera schlessera merged commit 1a15b15 into wp-cli:master Jul 31, 2018

1 check passed

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

This comment has been minimized.

Copy link
Member

schlessera commented Jul 31, 2018

Thanks for the pull-request, @greatislander !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.