Skip to content

Commit

Permalink
Update help text and dyno type/process type flag names (#3068)
Browse files Browse the repository at this point in the history
* Switch to --process-type and --dyno-name for stop and restart.

* Update logs to use --dyno-name and --process-type

* Update tests, fix logs alias

* Update command output to reflect new description

* Update dyno type to process type

* Fix tests
  • Loading branch information
eablack authored Nov 1, 2024
1 parent 086dfb1 commit 481cbf2
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 64 deletions.
16 changes: 9 additions & 7 deletions packages/cli/src/commands/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ export default class Logs extends Command {
static examples = [
'heroku logs --app=my-app',
'heroku logs --num=50 --app=my-app',
'heroku logs --dyno=web-123-456 --app=my-app',
'heroku logs --type=web --app=my-app',
'heroku logs --dyno-name=web-123-456 --app=my-app',
'heroku logs --process-type=web --app=my-app',
'heroku logs --app=my-app --tail',
]

static flags = {
app: flags.app({required: true}),
dyno: flags.string({
'dyno-name': flags.string({
aliases: ['dyno'],
char: 'd',
description: 'only show output from this dyno (such as "web-123-456" or "worker.2")',
}),
Expand All @@ -45,7 +46,7 @@ export default class Logs extends Command {
hidden: true,
description: 'hidden alias for type',
relationships: [
{type: 'none', flags: ['dyno']},
{type: 'none', flags: ['dyno-name']},
],
completion: ProcessTypeCompletion,
}),
Expand All @@ -59,18 +60,19 @@ export default class Logs extends Command {
default: false,
description: 'continually stream logs (defaults to true for Fir generation apps)',
}),
type: flags.string({
'process-type': flags.string({
char: 'p',
description: 'only show output from this process type (such as "web" or "worker")',
relationships: [
{type: 'none', flags: ['dyno', 'ps']},
{type: 'none', flags: ['dyno-name', 'ps']},
],
completion: ProcessTypeCompletion,
}),
}

async run() {
const {flags} = await this.parse(Logs)
const {app, dyno, 'force-colors': forceColors, num, ps, source, tail, type} = flags
const {app, 'dyno-name': dyno, 'force-colors': forceColors, num, ps, source, tail, 'process-type': type} = flags

if (forceColors)
color.enabled = true
Expand Down
25 changes: 13 additions & 12 deletions packages/cli/src/commands/ps/restart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {ProcessTypeCompletion} from '@heroku-cli/command/lib/completions'
import heredoc from 'tsheredoc'
export default class Restart extends Command {
static description = heredoc(`
restart app dynos
restart an app dyno or process type
if neither --dyno nor --type are specified, restarts all dynos on app
`)

Expand All @@ -15,34 +15,35 @@ export default class Restart extends Command {
static hiddenAliases = ['restart']

static examples = [
'$ heroku ps:restart --app myapp --dyno web.1',
'$ heroku ps:restart --app myapp --type web',
'$ heroku ps:restart --app myapp --dyno-name web.1',
'$ heroku ps:restart --app myapp --process-type web',
'$ heroku ps:restart --app myapp',
]

static args = {
dyno: Args.string({required: false, deprecated: true}),
dyno: Args.string({description: 'name of the dyno to restart', required: false, deprecated: true}),
}

static flags = {
app: flags.app({required: true}),
remote: flags.remote(),
dyno: flags.string({
'dyno-name': flags.string({
char: 'd',
description: 'restart a specific dyno (such as "web-123-456" or "worker.2")',
description: 'name of the dyno to restart',
}),
type: flags.string({
description: 'restart all dynos of a process type (such as "web" or "worker")',
'process-type': flags.string({
char: 'p',
description: 'name of the process type to restart',
completion: ProcessTypeCompletion,
exclusive: ['dyno'],
exclusive: ['dyno-name'],
}),
}

async run() {
const {args, flags} = await this.parse(Restart)
const app = flags.app
const dyno = flags.dyno || args.dyno
const type = flags.type
const dyno = flags['dyno-name'] || args.dyno
const type = flags['process-type']
let msg = 'Restarting'
let restartUrl

Expand All @@ -51,7 +52,7 @@ export default class Restart extends Command {
restartUrl = `/apps/${app}/formations/${encodeURIComponent(type)}`
} else if (dyno) {
if (args.dyno) {
ux.warn(`Passing DYNO as an arg is deprecated. Please use ${color.cmd('heroku ps:restart --dyno')} or ${color.cmd('heroku ps:restart --type')} instead.`)
ux.warn(`DYNO is a deprecated argument. Use ${color.cmd('--dyno-name')} or ${color.cmd('--process-type')} instead.`)
}

msg += ` dyno ${color.cyan(dyno)}`
Expand Down
27 changes: 14 additions & 13 deletions packages/cli/src/commands/ps/stop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,41 @@ import {ProcessTypeCompletion} from '@heroku-cli/command/lib/completions'
import heredoc from 'tsheredoc'

export default class Stop extends Command {
static description = 'stop app dyno or dyno type'
static description = 'stop an app dyno or process type'
static topic = 'ps'
static aliases = ['dyno:stop', 'ps:kill', 'dyno:kill']
static hiddenAliases = ['stop', 'kill']

static examples = [
'$ heroku ps:stop --app myapp --dyno run.1828',
'$ heroku ps:stop --app myapp --type run',
'$ heroku ps:stop --app myapp --dyno-name run.1828',
'$ heroku ps:stop --app myapp --process-type run',
]

static args = {
dyno: Args.string({required: false, deprecated: true}),
dyno: Args.string({description: 'name of the dyno to stop', required: false, deprecated: true}),
}

static flags = {
app: flags.app({required: true}),
remote: flags.remote(),
dyno: flags.string({
'dyno-name': flags.string({
char: 'd',
description: 'stop a specific dyno (such as "web-123-456" or "worker.2")',
description: 'name of the dyno to stop',
}),
type: flags.string({
description: 'stop all dynos of a process type (such as "web" or "worker")',
'process-type': flags.string({
char: 'p',
description: 'name of the process type to stop',
completion: ProcessTypeCompletion,
exclusive: ['dyno'],
exclusive: ['dyno-name'],
}),
}

async run() {
const {args, flags} = await this.parse(Stop)

const app = flags.app
const dyno = flags.dyno || args.dyno
const type = flags.type
const dyno = flags['dyno-name'] || args.dyno
const type = flags['process-type']
let msg = 'Stopping'
let stopUrl = ''

Expand All @@ -48,14 +49,14 @@ export default class Stop extends Command {
stopUrl = `/apps/${app}/formations/${encodeURIComponent(type)}/actions/stop`
} else if (dyno) {
if (args.dyno) {
ux.warn(`Passing DYNO as an arg is deprecated. Please use ${color.cmd('heroku ps:stop --dyno')} or ${color.cmd('heroku ps:stop --type')} instead.`)
ux.warn(`DYNO is a deprecated argument. Use ${color.cmd('--dyno-name')} or ${color.cmd('--process-type')} instead.`)
}

msg += ` dyno ${color.cyan(dyno)}`
stopUrl = `/apps/${app}/dynos/${encodeURIComponent(dyno)}/actions/stop`
} else {
ux.error(heredoc(`
Please specify a process type or dyno to stop.
Please specify a process type or dyno name to stop.
See more help with --help
`))
}
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/ps/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ const displayFormation = async (heroku: APIClient, app: string) => {
throw emptyFormationErr(app)
}

ux.styledHeader('Dyno Types')
ux.styledHeader('Process Types')
ux.table(formationTableData, {
type: {},
size: {},
qty: {},
'cost/hour': {},
'max cost/month': {},
})

ux.log()
ux.styledHeader('Dyno Totals')
ux.table(dynoTotalsTableData, {
type: {},
Expand Down
12 changes: 6 additions & 6 deletions packages/cli/test/acceptance/commands-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ domains:wait wait for domain to be active for
drains display the log drains of an app
drains:add adds a log drain to an app
drains:remove removes a log drain from an app
dyno:kill stop app dyno or dyno type
dyno:kill stop an app dyno or process type
dyno:resize manage dyno sizes
dyno:restart restart app dynos
dyno:restart restart an app dyno or process type
dyno:scale scale dyno quantity up or down
dyno:stop stop app dyno or dyno type
dyno:stop stop an app dyno or process type
features list available app features
features:disable disables an app feature
features:enable enables an app feature
Expand Down Expand Up @@ -238,12 +238,12 @@ ps:autoscale:enable enable web dyno autoscaling
ps:copy Copy a file from a dyno to the local filesystem
ps:exec Create an SSH session to a dyno
ps:forward Forward traffic on a local port to a dyno
ps:kill stop app dyno or dyno type
ps:kill stop an app dyno or process type
ps:resize manage dyno sizes
ps:restart restart app dynos
ps:restart restart an app dyno or process type
ps:scale scale dyno quantity up or down
ps:socks Launch a SOCKS proxy into a dyno
ps:stop stop app dyno or dyno type
ps:stop stop an app dyno or process type
ps:type manage dyno sizes
ps:wait wait for all dynos to be running latest version after a release
psql open a psql shell to the database
Expand Down
24 changes: 12 additions & 12 deletions packages/cli/test/unit/commands/logs.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ describe('logs', function () {
})
})

context('with --dyno option', function () {
context('with --dyno-name option', function () {
it('calls logDisplayer function with dyno filter set', async function () {
await runCommand(Cmd, [
'--app=my-app',
'--dyno=web.2',
'--dyno-name=web.2',
])

expect(logDisplayerStub.calledWith(sinon.match.any, {
Expand All @@ -81,7 +81,7 @@ describe('logs', function () {
it('calls logDisplayer function with type filter set', async function () {
await runCommand(Cmd, [
'--app=my-app',
'--type=web',
'--process-type=web',
])

expect(logDisplayerStub.calledWith(sinon.match.any, {
Expand Down Expand Up @@ -113,34 +113,34 @@ describe('logs', function () {
})
})

context('with both --dyno and --ps options', function () {
context('with both --dyno-name and --ps options', function () {
it('shows an error and doesn’t call logDisplayer function', async function () {
try {
await runCommand(Cmd, [
'--app=my-app',
'--dyno=web.1',
'--dyno-name=web.1',
'--ps=worker',
])
} catch (error: unknown) {
const {message} = error as CLIError
expect(message).to.include('--dyno=web.1 cannot also be provided when using --ps')
expect(message).to.include('--dyno-name=web.1 cannot also be provided when using --ps')
}

expect(logDisplayerStub.notCalled).to.be.true
})
})

context('with both --dyno and --type options', function () {
context('with both --dyno-name and --type options', function () {
it('shows an error and doesn’t call logDisplayer function', async function () {
try {
await runCommand(Cmd, [
'--app=my-app',
'--dyno=web.1',
'--type=worker',
'--dyno-name=web.1',
'--process-type=worker',
])
} catch (error: unknown) {
const {message} = error as CLIError
expect(message).to.include('--dyno=web.1 cannot also be provided when using --type')
expect(message).to.include('--dyno-name=web.1 cannot also be provided when using --process-type')
}

expect(logDisplayerStub.notCalled).to.be.true
Expand All @@ -153,11 +153,11 @@ describe('logs', function () {
await runCommand(Cmd, [
'--app=my-app',
'--ps=web',
'--type=worker',
'--process-type=worker',
])
} catch (error: unknown) {
const {message} = error as CLIError
expect(message).to.include('--ps=web cannot also be provided when using --type')
expect(message).to.include('--ps=web cannot also be provided when using --process-type')
}

expect(logDisplayerStub.notCalled).to.be.true
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/test/unit/commands/ps/restart.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('ps:restart', function () {
await runCommand(Cmd, [
'--app',
'myapp',
'--type',
'--process-type',
'web',
])
expectOutput(stderr.output, heredoc(`
Expand All @@ -48,7 +48,7 @@ describe('ps:restart', function () {
await runCommand(Cmd, [
'--app',
'myapp',
'--dyno',
'--dyno-name',
'web.1',
])
expectOutput(stderr.output, heredoc(`
Expand All @@ -67,7 +67,7 @@ describe('ps:restart', function () {
'myapp',
'web.1',
])
expect(stripAnsi(stderr.output)).to.include('Warning: Passing DYNO as an arg is deprecated.')
expect(stripAnsi(stderr.output)).to.include('DYNO is a deprecated argument.')
expect(stderr.output).to.include('Restarting dyno web.1 on ⬢ myapp... done')
})
})
8 changes: 4 additions & 4 deletions packages/cli/test/unit/commands/ps/stop.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('ps:stop', function () {
'--app',
'myapp',
]).catch(error => {
expect(error.message).to.include('Please specify a process type or dyno to stop.')
expect(error.message).to.include('Please specify a process type or dyno name to stop.')
})
})

Expand All @@ -25,7 +25,7 @@ describe('ps:stop', function () {
await runCommand(Cmd, [
'--app',
'myapp',
'--type',
'--process-type',
'web',
])
expectOutput(stderr.output, heredoc(`
Expand All @@ -42,7 +42,7 @@ describe('ps:stop', function () {
await runCommand(Cmd, [
'--app',
'myapp',
'--dyno',
'--dyno-name',
'web.1',
])
expectOutput(stderr.output, heredoc(`
Expand All @@ -61,7 +61,7 @@ describe('ps:stop', function () {
'myapp',
'web.1',
])
expect(stripAnsi(stderr.output)).to.include('Warning: Passing DYNO as an arg is deprecated.')
expect(stripAnsi(stderr.output)).to.include('Warning: DYNO is a deprecated argument.')
expect(stderr.output).to.include('Stopping dyno web.1 on ⬢ myapp... done')
})
})
Loading

0 comments on commit 481cbf2

Please sign in to comment.