-
Notifications
You must be signed in to change notification settings - Fork 52
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
Conversation
src/MakePotCommand.php
Outdated
@@ -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 ); |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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.
src/MakePotCommand.php
Outdated
$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 ); |
There was a problem hiding this comment.
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? :-)
Thanks @greatislander! This is coming along nicely. |
- Use WP-CLI utility functions where possible - Fix inadvertent whitespace changes - Revert accidental composer.json changes
@swissspidy Updated based on your feedback -- let me know if there's any other changes you'd like! |
Thanks for the pull-request, @greatislander ! |
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.