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
Merged

Conversation

greatislander
Copy link

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 );
Copy link
Member

Choose a reason for hiding this comment

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

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"
Copy link
Member

Choose a reason for hiding this comment

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

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 );
Copy link
Member

Choose a reason for hiding this comment

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

Unintended whitespace changes I guess? :-)

@swissspidy
Copy link
Member

Thanks @greatislander! This is coming along nicely.

- Use WP-CLI utility functions where possible
- Fix inadvertent whitespace changes
- Revert accidental composer.json changes
@greatislander
Copy link
Author

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

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

Thanks for the pull-request, @greatislander !

schlessera added a commit that referenced this pull request Jan 6, 2022
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.

Allow passing custom headers and comments for POT file
3 participants