civicrm / cv

CiviCRM CLI Utility
28 stars 30 forks source link

APIv4 --out=table prints a non-markdown-compatible table #182

Open colemanw opened 1 year ago

colemanw commented 1 year ago

What would it take for the table output to be compatible with markdown? That seems like a more useful format?

Currently the table output looks like this:

+-------+----------------+----------------+
| value | name           | label          |
+-------+----------------+----------------+
| 1     | Completed      | Completed      |
| 2     | Pending        | Pending        |
| 3     | Cancelled      | Cancelled      |
| 4     | Failed         | Failed         |
| 7     | Refunded       | Refunded       |
| 8     | Partially paid | Partially paid |
| 9     | Pending refund | Pending refund |
| 10    | Chargeback     | Chargeback     |
| 11    | Template       | Template       |
+-------+----------------+----------------+

Which is nice-looking ascii art, but when you paste it into GitLab, GitHub or any other type of markdown document, it looks like this:

+-------+----------------+----------------+ | value | name | label | +-------+----------------+----------------+ | 1 | Completed | Completed | | 2 | Pending | Pending | | 3 | Cancelled | Cancelled | | 4 | Failed | Failed | | 7 | Refunded | Refunded | | 8 | Partially paid | Partially paid | | 9 | Pending refund | Pending refund | | 10 | Chargeback | Chargeback | | 11 | Template | Template | +-------+----------------+----------------+

totten commented 1 year ago

Markdown compat is a neat idea

FWIW, the table is rendered using Symfony's Table helper:

My guess is that either (a) there's some kind of existing "style"/renderer for Markdown or (b) you could tune options like setDefaultCrossingChar('|') to make a Markdown-friendly layout. The main thing to look out for is line-wrapping data -- iirc, Markdown's text doesn't really allow wrapping. This would be a colorful demonstration where I think they diverge:

cv api4 MessageTemplate.get -T +s id,msg_html +l 2

There are a few alternate possibilities:

  1. If there's a format that handles newlines suitably for both text-console and Markdown-renderers, then change the current table output to use that.
  2. Tweak the current the output to be closer to Markdown in the average case (single-line content) and accept that some output won't transfer over to *.md.
  3. Provide an alternate output (--out=md) optimized for Markdown. (This might allow for other adaptations, like backtick escaping?)