Skip to content

Conversation

erika-wallace
Copy link
Contributor

Description

W-19830244

This PR reimplements --csv for heroku domains, since it was removed from oclif during the migration to v4. It allows users to output domain data in CSV format and export to a .csv file.

Type of change:

Refactor

Testing

NOTE: You will need an app with multiple domains (at least 3-4 to test sorting).

Test CSV output:

  1. checkout this branch and run npm install && npm run build
  2. Run ./bin/run domains -a <your-app> --csv, confirm CSV output with headers
  3. Run ./bin/run domains -a <your-app> --csv > test-output.csv, confirm file was created successfully and opens with proper CSV format

Test CSV sorting:

  1. Run ./bin/run domains -a <your-app> --csv --sort "Domain Name", confirm CSV output was sorted by the Domain Name column (direct property)
  2. Run ./bin/run domains -a <your-app> --csv --sort "DNS Record Type", confirm CSV output was sorted by the DNS Record Type column (not a direct property)

Test CSV with other flags:

  1. Run ./bin/run domains -a <your-app> --csv --extended, confirm output includes additional columns (ACM Status, ACM Status Reason)
  2. Run ./bin/run domains -a <your-app> --csv --columns "Domain Name,DNS Target", confirm output only shows specified columns
  3. Run ./bin/run domains -a <your-app> --csv --filter "Domain Name=example", confirm output only shows domains matching the filter criteria

Verify no regressions:

  1. Run ./bin/run domains -a <your-app>, confirm table output still works
  2. Run ./bin/run domains -a <your-app> --sort "Domain Name", confirm table sorting still works

@erika-wallace erika-wallace requested a review from a team as a code owner October 16, 2025 18:20
@erika-wallace
Copy link
Contributor Author

erika-wallace commented Oct 16, 2025

Note: The sorting for CSV is different from the table sorting, so the outputs don't match exactly. The table is sorted by oclif/table, which uses the natural-orderby package. Let me know if we should align them. I can import natural-orderby for CSV too.

}

const escapeCSV = (value: string) => {
const needsEscaping = value.includes('"') || value.includes('\n') || value.includes('\r') || value.includes(',')
Copy link
Contributor

Choose a reason for hiding this comment

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

We can simplify this using some regex like so: const needsEscaping = /["\n\r,]/.test(value)

if (customDomains.length > 100 && !flags.json) {
ux.warn(`This app has over 100 domains. Your terminal may not be configured to display the total amount of domains. You can output domains in JSON format with: ${color.cmd('heroku domains -a example-app --json')}`)
if (customDomains.length > 100 && !flags.json && !flags.csv) {
ux.warn(`This app has over 100 domains. Your terminal may not be configured to display the total amount of domains. You can export all domains into a CSV file with: ${color.cmd('heroku domains -a example-app --csv > example-file.csv')}`)
Copy link
Contributor

Choose a reason for hiding this comment

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

We should leave the JSON copy as is because that was the initial flow for users with over 100 domains. The previous functionality still had CSV formatting available, but wasn't highlighted in the warning. They also can view that format option in the --help CSV flag description.


outputCSV = (customDomains: Heroku.Domain[], tableConfig: Record<string, any>, sortProperty?: string) => {
const getValue = (domain: Heroku.Domain, key: string, config?: Record<string, any>) => {
const cfg = config ?? tableConfig[key]
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make cfg a little more descriptive? Like tableConfigValue or columnValue? This will help us maintain readability.

Copy link
Contributor

@zwhitfield3 zwhitfield3 left a comment

Choose a reason for hiding this comment

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

Fantastic work here! Well organized and refactored. I requested a few changes, but otherwise, this PR is looking good! I think we should maintain the same sorting between the table and CSV to maintain consistency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants