Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add logging of search-replace transformations.#35

Merged
danielbachhuber merged 4 commits into
masterwp-cli/search-replace-command:masterfrom
issue_1wp-cli/search-replace-command:issue_1Copy head branch name to clipboard
Oct 12, 2017
Merged

Add logging of search-replace transformations.#35
danielbachhuber merged 4 commits into
masterwp-cli/search-replace-command:masterfrom
issue_1wp-cli/search-replace-command:issue_1Copy head branch name to clipboard

Conversation

@gitlost

@gitlost gitlost commented Sep 19, 2017

Copy link
Copy Markdown
Contributor

Fixes #1

Adds logging of before/after changes.

@danielbachhuber

Copy link
Copy Markdown
Member

@gitlost Can you share a screencast?

@gitlost

gitlost commented Oct 4, 2017

Copy link
Copy Markdown
Contributor Author

Did an asciinema https://asciinema.org/a/140798

@danielbachhuber

Copy link
Copy Markdown
Member

@gitlost That's pretty fantastic.

@gitlost

gitlost commented Oct 4, 2017

Copy link
Copy Markdown
Contributor Author

Shucks, I'll request a review so!

@gitlost gitlost requested a review from a team October 4, 2017 13:22

@miya0001 miya0001 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I like it! :)

@danielbachhuber

Copy link
Copy Markdown
Member

Let's get a couple more reviews on this too.

@danielbachhuber danielbachhuber left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Some small nits about usage; otherwise, this looks great :)

Comment thread src/Search_Replace_Command.php Outdated
* '%8' Reverse
* '%U' Underline
* '%F' Blink (unlikely to work)
* They can be concatenated.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

"They can be concatenated" needs an additional newline.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This whole color stuff can now be just dropped.

Comment thread src/Search_Replace_Command.php Outdated
* Warning: causes a significant slow down, similar or worse to enabling --precise or --regex.
*
* [--log_context=<before_num,after_num>]
* : Number of characters to display before and after the match. One number sets both before and after. Two comma-separated numbers set before and after respectively. Defaults to 40. Ignored if not logging.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  1. For consistency, should we follow --before_context=<num> and --after_context=<num> as established by wp db search ? I rather like --log_context=<> better, but I think we should opt for consistency whenever possible.
  2. We should wrap the argument description at whatever count we use for the others.

@gitlost gitlost Oct 11, 2017

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we should opt for consistency

Am going to propose adding the same "shortcut" version --context to wp db search (also a shortcut ---colors). This would make them more or less consistent (barring the log_ prefix), with db search having a superset.

(The main motivation for not just using log_context_before etc was as you mention below the large amount of options that search-replace already has.)

The log_ prefix seemed needed to give clarity to and group the options and is sort of consistent with db search (which doesn't have a log option) but I'll drop if you think it's confusing/inconsistent.

Edit okay given the other log options are being dropped, I'll drop --log_context and just do --context_before and --context_after.

wrap the argument description

Will do.

(Probably the same/similar newline stripping as is now done for the handbook should be done for help in general, as the some-do, some-don't wrapping currently on help looks odd.)

Comment thread src/Search_Replace_Command.php Outdated
* [--log_context=<before_num,after_num>]
* : Number of characters to display before and after the match. One number sets both before and after. Two comma-separated numbers set before and after respectively. Defaults to 40. Ignored if not logging.
*
* [--log_prefixes=<old_prefix,new_prefix>]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this necessary as a command argument, or could it be an environment variable instead?

The command arguments available to wp search-replace have become a bit overwhelming. We may need to more actively address this in the future.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's easily changed to be an environment variable instead, so will do.

The command arguments available to wp search-replace have become a bit overwhelming.

Yes, the synopsis isn't easy to parse, especially with all those square brackets. Was thinking some auto-embolding (similar to most Unix man pages) would help but not sure:

wp search-replace <old> <new> [<table>...] [--dry-run] [--network] [--all-tables-with-prefix] [--all-tables] [--export[=]] [--export_insert_size=] [--skip-columns=]
[--include-columns=] [--precise] [--recurse-objects] [--verbose] [--regex] [--regex-flags=] [--regex-delimiter=] [--format=] [--report]
[--report-changed-only] [--log[=]] [--log_context=<before_num,after_num>] [--log_prefixes=<old_prefix,new_prefix>] [--log_colors=<table_column_id_color,old_color,new_color>]

and similarly for the line-by-line options. I actually prototyped something like this a long time ago (when doing the word-wrapping) so will dig it up if you think it's worthwhile.

Comment thread src/Search_Replace_Command.php Outdated
* [--log_prefixes=<old_prefix,new_prefix>]
* : The old and new prefixes to prepend to the log lines for old match and new replacement, comma-separated. Defaults to '< ,> '. Use ',' for no prefixes. Ignored if not logging.
*
* [--log_colors=<table_column_id_color,old_color,new_color>]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same comment as above: does this need to be a command argument?

I think my preference would be to remove this as an option entirely. We can bring it up again in the future if anyone brings it up.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Okay, will do.

@danielbachhuber danielbachhuber added this to the 1.1.0 milestone Oct 10, 2017
@danielbachhuber danielbachhuber added the command:search-replace Related to 'search-replace' command label Oct 10, 2017
@danielbachhuber

Copy link
Copy Markdown
Member

💯 Great work on this, @gitlost.

@schlessera

Copy link
Copy Markdown
Member

Finally got around to test this (didn't have enough data bandwidth for the Composer update yesterday).

I agree, @gitlost, this is great, and a huge improvement on the existing behaviour for more risky replacements.

danielbachhuber added a commit that referenced this pull request Nov 18, 2022
Add logging of search-replace transformations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command:search-replace Related to 'search-replace' command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.