Skip to content

Commit

Permalink
use cli-table3 to display domain records
Browse files Browse the repository at this point in the history
  • Loading branch information
tbeseda committed Jul 27, 2023
1 parent 82e3e8d commit 47111d4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 26 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@begin/api": "1.9.1",
"@enhance/starter-project": "5.1.4",
"adm-zip": "0.5.10",
"cli-table3": "0.6.3",
"enquirer": "2.3.6",
"escodegen": "2.0.0",
"esprima": "4.0.1",
Expand Down
36 changes: 10 additions & 26 deletions src/commands/domains/records.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
const visibleTypes = [
'TXT',
'MX',
'ALIAS',
'NS',
'SPF',
]
const visibleTypes = [ 'TXT', 'MX', 'ALIAS', 'NS', 'SPF' ]

async function action (params) {
let c = require('picocolors')
Expand Down Expand Up @@ -49,14 +43,7 @@ async function action (params) {
// @ts-ignore
_staging,
domainID: theDomain.domainID,
changes: [
{
type,
name,
value,
ttl,
}
]
changes: [ { type, name, value, ttl } ],
})

return `Added record ${c.bold(type)} ${c.cyan(name)} (${result.status})`
Expand All @@ -67,18 +54,12 @@ async function action (params) {
// @ts-ignore
_staging,
domainID: theDomain.domainID,
record: {
type,
name,
value,
ttl,
}
record: { type, name, value, ttl },
})

return `Removed record ${c.bold(type)} ${c.cyan(name)} (${result.status})`
}
else {
// list records
else { // list records
let records = await client.domains.records.list({ token, _staging, domainID: theDomain.domainID })
let outputRecords = verbose ? records : records.filter(r => visibleTypes.includes(r.type))
outputRecords = outputRecords.sort((a, b) => a.type.localeCompare(b.type))
Expand All @@ -87,9 +68,12 @@ async function action (params) {
return c.red(`No records found for ${c.underline(c.cyan(domain))}`)
}
else {
return outputRecords.map(r =>
`${c.bold(r.type)} ${c.cyan(r.name)} ${c.italic(r.ttl || '')} ${r.values?.join(' ') || ''}`
).join('\n')
let Table = require('cli-table3')
let table = new Table({ head: [ 'Type', 'Name', 'TTL', 'Value' ] })
for (const r of outputRecords)
table.push([ c.bold(r.type), c.cyan(r.name), r.ttl, r.values?.join('\n') ])

return table.toString()
}
}
}
Expand Down

0 comments on commit 47111d4

Please sign in to comment.