Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/commands/addons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ async function addonGetter(api: APIClient, app?: string) {
return addons
}

function displayAll(addons: Heroku.AddOn[]) {
function displayAll(addons: Heroku.AddOn[], noWrap = false) {
addons = _.sortBy(addons, 'app.name', 'plan.name', 'addon.name')
if (addons.length === 0) {
ux.stdout('No add-ons.')
Expand Down Expand Up @@ -139,7 +139,8 @@ function displayAll(addons: Heroku.AddOn[]) {
},
},
{
overflow: 'wrap',
maxWidth: noWrap ? 'none' : undefined,
overflow: noWrap ? 'truncate' : 'wrap',
},
)
/* eslint-enable perfectionist/sort-objects */
Expand All @@ -162,7 +163,7 @@ export function renderAttachment(attachment: Heroku.AddOnAttachment, app: string
return ` ${color.dim(line)} ${attName}`
}

function displayForApp(app: string, addons: Heroku.AddOn[]) {
function displayForApp(app: string, addons: Heroku.AddOn[], noWrap = false) {
if (addons.length === 0) {
ux.stdout(`No add-ons for app ${app}.`)
return
Expand Down Expand Up @@ -222,7 +223,8 @@ function displayForApp(app: string, addons: Heroku.AddOn[]) {
},
},
{
overflow: 'wrap',
maxWidth: noWrap ? 'none' : undefined,
overflow: noWrap ? 'truncate' : 'wrap',
},
)
ux.stdout(`The table above shows add-ons and the attachments to the current app (${color.app(app)}) or other apps.\n `)
Expand All @@ -249,6 +251,7 @@ export default class Addons extends Command {
all: flags.boolean({char: 'A', description: 'show add-ons and attachments for all accessible apps'}),
app: flags.app(),
json: flags.boolean({description: 'return add-ons in json format'}),
'no-wrap': flags.boolean({description: 'disable wrapped table cells for easier copy/paste'}),
remote: flags.remote(),
}

Expand All @@ -265,13 +268,13 @@ export default class Addons extends Command {
if (json)
displayJSON(addons)
else
displayForApp(app, addons)
displayForApp(app, addons, flags['no-wrap'])
} else {
const addons = await addonGetter(this.heroku)
if (json)
displayJSON(addons)
else
displayAll(addons)
displayAll(addons, flags['no-wrap'])
}
}
}
4 changes: 3 additions & 1 deletion src/commands/data/pg/credentials/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default class DataPgCredentialsIndex extends BaseCommand {

static flags = {
app: Flags.app({required: true}),
'no-wrap': Flags.boolean({description: 'disable wrapped table cells for easier copy/paste'}),
remote: Flags.remote(),
}

Expand Down Expand Up @@ -75,7 +76,8 @@ export default class DataPgCredentialsIndex extends BaseCommand {
get: cred => cred.state,
},
}, {
overflow: 'wrap',
maxWidth: flags['no-wrap'] ? 'none' : undefined,
overflow: flags['no-wrap'] ? 'truncate' : 'wrap',
})
}
}
4 changes: 3 additions & 1 deletion src/commands/domains/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ www.example.com CNAME www.example.herokudns.com`]
extended: flags.boolean({char: 'x', description: 'show extra columns'}),
filter: flags.string({description: 'filter property by partial string matching, ex: name=foo'}),
json: flags.boolean({char: 'j', description: 'output in json format'}),
'no-wrap': flags.boolean({description: 'disable wrapped table cells for easier copy/paste'}),
remote: flags.remote(),
sort: flags.string({description: 'sort by property'}),
}
Expand Down Expand Up @@ -222,7 +223,8 @@ www.example.com CNAME www.example.herokudns.com`]
this.outputCSV(customDomains, tableConfig, sortProperty)
} else {
hux.table(customDomains, tableConfig, {
overflow: 'wrap',
maxWidth: flags['no-wrap'] ? 'none' : undefined,
overflow: flags['no-wrap'] ? 'truncate' : 'wrap',
sort: flags.sort ? {[sortProperty]: 'asc'} : undefined,
})
}
Expand Down
4 changes: 3 additions & 1 deletion src/commands/pg/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default class Credentials extends Command {
static description = 'show information on credentials in the database'
static flags = {
app: flags.app({required: true}),
'no-wrap': flags.boolean({description: 'disable wrapped table cells for easier copy/paste'}),
remote: flags.remote(),
}

Expand Down Expand Up @@ -63,7 +64,8 @@ export default class Credentials extends Command {
get: cred => cred.state,
},
}, {
overflow: 'wrap',
maxWidth: flags['no-wrap'] ? 'none' : undefined,
overflow: flags['no-wrap'] ? 'truncate' : 'wrap',
})
}

Expand Down
8 changes: 5 additions & 3 deletions src/commands/ps/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function truncate(s: string) {
return s.length > 35 ? `${s.slice(0, 34)}…` : s
}

function printExtended(dynos: DynoExtended[]) {
function printExtended(dynos: DynoExtended[], noWrap = false) {
const sortedDynos = dynos.sort(byProcessTypeAndNumber)

/* eslint-disable perfectionist/sort-objects */
Expand All @@ -80,7 +80,8 @@ function printExtended(dynos: DynoExtended[]) {
Size: {get: (dyno: DynoExtended) => dyno.size},
},
{
overflow: 'wrap',
maxWidth: noWrap ? 'none' : undefined,
overflow: noWrap ? 'truncate' : 'wrap',
},
)
/* eslint-enable perfectionist/sort-objects */
Expand Down Expand Up @@ -184,6 +185,7 @@ export default class Index extends Command {
app: flags.app({required: true}),
extended: flags.boolean({char: 'x', hidden: true}), // only works with sudo privileges
json: flags.boolean({description: 'display as json'}),
'no-wrap': flags.boolean({description: 'disable wrapped table cells for easier copy/paste'}),
remote: flags.remote(),
}

Expand Down Expand Up @@ -234,7 +236,7 @@ export default class Index extends Command {
if (json)
hux.styledJSON(selectedDynos)
else if (extended)
printExtended(selectedDynos)
printExtended(selectedDynos, flags['no-wrap'])
else {
await printAccountQuota(this.heroku, appInfo, accountInfo)
if (selectedDynos.length === 0)
Expand Down
11 changes: 11 additions & 0 deletions test/unit/commands/addons/index.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* eslint-disable max-nested-callbacks */
import * as Heroku from '@heroku-cli/schema'
import {expect} from 'chai'
import {hux} from '@heroku/heroku-cli-util'
import nock from 'nock'
import sinon from 'sinon'

import Cmd from '../../../../src/commands/addons/index.js'
import * as fixtures from '../../../fixtures/addons/fixtures.js'
Expand All @@ -24,6 +26,7 @@ describe('addons', function () {
afterEach(function () {
api.done()
nock.cleanAll()
sinon.restore()
})

describe('--all', function () {
Expand Down Expand Up @@ -59,6 +62,14 @@ describe('addons', function () {
expect(stdout.indexOf('acme-inc-api')).to.be.lt(stdout.indexOf('acme-inc-www'))
expect(stdout.indexOf('www-db')).to.be.lt(stdout.indexOf('www-redis'))
})
it('passes no-wrap option through to table rendering', async function () {
const tableStub = sinon.stub(hux, 'table')

await runCommand(Cmd, ['--all', '--no-wrap'])

const callArgs = tableStub.firstCall.args
expect(callArgs[2]).to.include({maxWidth: 'none', overflow: 'truncate'})
})
context('--json', function () {
it('prints the output in json format', async function () {
const {stdout} = await runCommand(Cmd, [
Expand Down
27 changes: 27 additions & 0 deletions test/unit/commands/data/pg/credentials/index.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import ansis from 'ansis'
import {expect} from 'chai'
import {hux} from '@heroku/heroku-cli-util'
import nock from 'nock'
import sinon from 'sinon'
import {stdout} from 'stdout-stderr'
import tsheredoc from 'tsheredoc'

Expand All @@ -18,6 +20,10 @@ import removeAllWhitespace from '../../../../../helpers/utils/remove-whitespaces
const heredoc = tsheredoc.default

describe('data:pg:credentials:index', function () {
afterEach(function () {
sinon.restore()
})

it('shows error for non-advanced databases', async function () {
const herokuApi = nock('https://api.heroku.com')
.post('/actions/addons/resolve')
Expand Down Expand Up @@ -97,4 +103,25 @@ describe('data:pg:credentials:index', function () {
herokuApi.done()
dataApi.done()
})

it('passes no-wrap option through to table rendering', async function () {
const herokuApi = nock('https://api.heroku.com')
.post('/actions/addons/resolve')
.reply(200, [addon])
.get(`/addons/${addon.id}/addon-attachments`)
.reply(200, advancedCredentialsAttachmentsResponse)

const dataApi = nock('https://api.data.heroku.com')
.get(`/data/postgres/v1/${addon.id}/credentials`)
.reply(200, advancedCredentialsResponse)

const tableStub = sinon.stub(hux, 'table')
await runCommand(DataPgCredentialsIndex, ['DATABASE', '--app=myapp', '--no-wrap'])

const callArgs = tableStub.firstCall.args
expect(callArgs[2]).to.include({maxWidth: 'none', overflow: 'truncate'})

herokuApi.done()
dataApi.done()
})
})
14 changes: 14 additions & 0 deletions test/unit/commands/domains/index.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {expect} from 'chai'
import nock from 'nock'
import sinon from 'sinon'
import {stderr, stdout} from 'stdout-stderr'
import {hux} from '@heroku/heroku-cli-util'

import DomainsIndex from '../../../../src/commands/domains/index.js'
import {runCommand} from '../../../helpers/run-command.js'
Expand Down Expand Up @@ -195,4 +196,17 @@ describe('domains', function () {
'Warning: This app has over 100 domains. Your terminal may not be configured to display the total amount of domains.',
)
})

it('passes no-wrap option through to table rendering', async function () {
api.get('/apps/myapp/domains').reply(200, herokuAndCustomDomainsResponse)
const tableStub = sinon.stub(hux, 'table')

await runCommand(DomainsIndex, ['--app', 'myapp', '--no-wrap'])

expect(tableStub.calledOnce).to.equal(true)
const callArgs = tableStub.firstCall.args
expect(callArgs[2]).to.include({maxWidth: 'none', overflow: 'truncate'})

tableStub.restore()
})
})
25 changes: 25 additions & 0 deletions test/unit/commands/pg/credentials.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import {stdout} from 'stdout-stderr'
import runCommand from '../../../helpers/runCommand.js'
import {expect} from 'chai'
import nock from 'nock'
import sinon from 'sinon'
import {hux} from '@heroku/heroku-cli-util'
import Cmd from '../../../../src/commands/pg/credentials.js'
import tsheredoc from 'tsheredoc'
import normalizeTableOutput from '../../../helpers/utils/normalizeTableOutput.js'
Expand Down Expand Up @@ -29,6 +31,7 @@ describe('pg:credentials', function () {

afterEach(function () {
nock.cleanAll()
sinon.restore()
pg.done()
api.done()
})
Expand Down Expand Up @@ -199,4 +202,26 @@ describe('pg:credentials', function () {
expect(normalized).to.include('heroku_postgresql_blue')
expect(normalized).to.include('yet-another')
})

it('passes no-wrap option through to table rendering', async function () {
const credentials = [
{uuid: 'aaaa', name: 'default', state: 'active', database: 'd123', host: 'localhost', port: 5442, credentials: []},
]
const attachments = [
{app: {name: 'main-app'}, name: 'DATABASE', namespace: null},
]

api.post('/actions/addon-attachments/resolve', {addon_attachment: 'DATABASE_URL', app: 'myapp'})
.reply(200, [{addon}])
.get('/addons/1/addon-attachments')
.reply(200, attachments)
pg.get('/postgres/v0/databases/1/credentials')
.reply(200, credentials)

const tableStub = sinon.stub(hux, 'table')
await runCommand(Cmd, ['--app', 'myapp', '--no-wrap'])

const callArgs = tableStub.firstCall.args
expect(callArgs[2]).to.include({maxWidth: 'none', overflow: 'truncate'})
})
})
38 changes: 38 additions & 0 deletions test/unit/commands/ps/index.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import ansis from 'ansis'
import {expect} from 'chai'
import {hux} from '@heroku/heroku-cli-util'
import nock from 'nock'
import {stderr, stdout} from 'stdout-stderr'
import strftime from 'strftime'
import tsheredoc from 'tsheredoc'
import sinon from 'sinon'

import Cmd from '../../../../src/commands/ps/index.js'
import runCommand from '../../../helpers/runCommand.js'
Expand Down Expand Up @@ -41,6 +43,7 @@ function stubAppAndAccount() {
describe('ps', function () {
afterEach(function () {
nock.cleanAll()
sinon.restore()
})

it('shows dyno list', async function () {
Expand Down Expand Up @@ -261,6 +264,41 @@ describe('ps', function () {
expect(stderr.output).to.equal('')
})

it('passes no-wrap option through to extended table rendering', async function () {
nock('https://api.heroku.com', {reqheaders: {accept: 'application/vnd.heroku+json; version=3.sdk'}})
.get('/account')
.reply(200, {id: '1234'})
.get('/apps/myapp')
.reply(200, {name: 'myapp'})
.get('/apps/myapp/dynos?extended=true')
.reply(200, [{
command: 'npm start',
extended: {
az: 'us-east',
execution_plane: 'execution_plane',
fleet: 'fleet',
instance: 'instance',
ip: '10.0.0.1',
port: 8000,
region: 'us',
route: 'da route',
},
id: '100',
name: 'web.1',
release: {id: '10', version: '40'},
size: 'Eco',
state: 'up',
type: 'web',
updated_at: hourAgo,
}])

const tableStub = sinon.stub(hux, 'table')
await runCommand(Cmd, ['--app', 'myapp', '--extended', '--no-wrap'])

const callArgs = tableStub.firstCall.args
expect(callArgs[2]).to.include({maxWidth: 'none', overflow: 'truncate'})
})

it('shows extended info for Private Space app', async function () {
const api = nock('https://api.heroku.com', {reqheaders: {accept: 'application/vnd.heroku+json; version=3.sdk'}})
.get('/account')
Expand Down
Loading