civicrm / cv

CiviCRM CLI Utility
28 stars 30 forks source link

Api4 - Don't crash when displaying an empty table #181

Closed totten closed 1 year ago

totten commented 1 year ago

The -T flag requests that results be displayed as a table. Consider these four commands:

  1. cv api4 Route.get +w 'name like %admin%' -T +s path
  2. cv api4 Route.get +w 'name like %admin%' -T
  3. cv api4 Route.get +w 'name like %zzz%' -T +s path
  4. cv api4 Route.get +w 'name like %zzz%' -T

How do they behave?

  1. Shows a table (with path header) and exits normally
  2. Shows a table (with many column headers) and exits normally
  3. Shows an empty table (with path header) and exits normally
  4. Crashes because it cannot pick a header. (At least, on php81 it does.) (array_keys(): Argument #1 ($array) must be of type array, null given)

This patch changes (4) to behave more like (3) -- it will show an empty table and exit normally.

colemanw commented 1 year ago

Looks good to me.

totten commented 1 year ago

civibot, test this please