Automattic / newspack-custom-content-migrator

Custom migration tasks for launching and migrating Newspack sites on Atomic
5 stars 5 forks source link

Add/console output table #398

Closed eddiesshop closed 9 months ago

eddiesshop commented 9 months ago

I created this class so that I can easily display arrays while in CLI/Terminal/Console in a table format. Sometimes I need to inspect, and compare values within arrays during migrations or simply when testing a change. I find it extremely helpful to be able to display this data vertically in a table. So the first function (output_comparison) in this class does just that: image In the screenshot, it is evident that this function does a few more things automatically to be able to display the data in a table format:

  1. Boolean values are converted to strings for display only (i.e. true becomes 'true', false becomes 'false')
  2. If an array does not have a value for a particular key, a dash ('-') is used to convey this.
  3. Arrays, and their keys, are handled dynamically. It doesn't matter if the arrays you need to compare don't have a single matching key.

The next function in this class (output_value_comparison) is helpful when you need to compare two array values side-by-side. The display of values is similar to the function above, the difference here is that you have a column which confirms whether the values match or not: Comparing `$first_array` against `$second_array` Comparing `$first_array` against `$third_array`

Another feature of this function is an array which is returned that contains all matching and differing values, as well as any values whose comparison could not be determined. image