-
Notifications
You must be signed in to change notification settings - Fork 231
refactor: reimplement csv option for domains #3388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v11.0.0
Are you sure you want to change the base?
Conversation
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 |
} | ||
|
||
const escapeCSV = (value: string) => { | ||
const needsEscaping = value.includes('"') || value.includes('\n') || value.includes('\r') || value.includes(',') |
There was a problem hiding this comment.
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')}`) |
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
Description
W-19830244
This PR reimplements
--csv
forheroku 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:
npm install && npm run build
./bin/run domains -a <your-app> --csv
, confirm CSV output with headers./bin/run domains -a <your-app> --csv > test-output.csv
, confirm file was created successfully and opens with proper CSV formatTest CSV sorting:
./bin/run domains -a <your-app> --csv --sort "Domain Name"
, confirm CSV output was sorted by the Domain Name column (direct property)./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:
./bin/run domains -a <your-app> --csv --extended
, confirm output includes additional columns (ACM Status, ACM Status Reason)./bin/run domains -a <your-app> --csv --columns "Domain Name,DNS Target"
, confirm output only shows specified columns./bin/run domains -a <your-app> --csv --filter "Domain Name=example"
, confirm output only shows domains matching the filter criteriaVerify no regressions:
./bin/run domains -a <your-app>
, confirm table output still works./bin/run domains -a <your-app> --sort "Domain Name"
, confirm table sorting still works