Skip to content

Commit

Permalink
chore(cli): enable backwards compatibility syntax for addons:create (#…
Browse files Browse the repository at this point in the history
…2972)

* Enable backwards compatibility for addons:create

* Add second portion of syntax deprecation message

* Bump heroku-cli-command dependency

* Update logic for displaying deprecation warning

* Debug

* Fix debugging

* Add test

* Update warning interface

* Update tests
  • Loading branch information
zwhitfield3 authored Aug 15, 2024
1 parent 2d58422 commit bdeeb09
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"bugs": "https://github.com/heroku/cli/issues",
"dependencies": {
"@heroku-cli/color": "2.0.1",
"@heroku-cli/command": "^11.1.2",
"@heroku-cli/command": "^11.2.2",
"@heroku-cli/notifications": "^1.2.4",
"@heroku-cli/plugin-ps": "^8.1.7",
"@heroku-cli/plugin-ps-exec": "^2.4.0",
Expand Down
6 changes: 6 additions & 0 deletions packages/cli/src/commands/addons/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,19 @@ export default class Create extends Command {
}

public async run(): Promise<void> {
this.allowArbitraryFlags = true
const {flags, args, ...restParse} = await this.parse(Create)
const {app, name, as, wait, confirm} = flags
const servicePlan = args['service:plan']
const argv = (restParse.argv as string[])
// oclif duplicates specified args in argv
.filter(arg => arg !== servicePlan)

if (restParse.nonExistentFlags && restParse.nonExistentFlags.length > 0) {
process.stderr.write(` ${color.yellow('›')} For example: ${color.cyan(`heroku addons:create -a ${app} ${restParse.raw[0].input} -- ${restParse.nonExistentFlags.join(' ')}`)}`)
process.stderr.write(` ${color.yellow('›')} See https://devcenter.heroku.com/changelog-items/2925 for more info.\n`)
}

const config = parseConfig(argv)
let addon
try {
Expand Down
18 changes: 18 additions & 0 deletions packages/cli/test/unit/commands/addons/create.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as _ from 'lodash'
import * as sinon from 'sinon'
import * as nock from 'nock'
import stripAnsi = require('strip-ansi')
import {unwrap} from '../../../helpers/utils/unwrap'
const lolex = require('lolex')

describe('addons:create', function () {
Expand Down Expand Up @@ -79,6 +80,23 @@ describe('addons:create', function () {
expect(stderr.output).to.contain('Creating heroku-postgresql:standard-0 on ⬢ myapp... ~$0.139/hour (max $100/month)\n')
expect(stdout.output).to.equal('provision message\nCreated db3-swiftly-123 as DATABASE_URL\nUse heroku addons:docs heroku-db3 to view documentation\n')
})
it('creates an add-on with proper output using old syntax with deprecation message', async function () {
await runCommand(Cmd, [
'--app',
'myapp',
'--as',
'mydb',
'heroku-postgresql:standard-0',
'--rollback',
'--follow',
'otherdb',
'--foo',
])
expect(unwrap(stderr.output)).to.contain('Warning: You’re using a deprecated syntax with the [--rollback,--follow,--foo] flag')
expect(unwrap(stderr.output)).to.contain("Add a '--' (end of options) separator before the flags you’re passing through.")
expect(unwrap(stderr.output)).to.contain('For example: heroku addons:create -a myapp heroku-postgresql:standard-0 -- --rollback --follow otherdb --foo')
expect(unwrap(stderr.output)).to.contain('See https://devcenter.heroku.com/changelog-items/2925 for more info.')
})
it('creates an addon with = args', async function () {
await runCommand(Cmd, [
'--app',
Expand Down
13 changes: 8 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1616,9 +1616,9 @@ __metadata:
languageName: node
linkType: hard

"@heroku-cli/command@npm:^11.1.2":
version: 11.1.2
resolution: "@heroku-cli/command@npm:11.1.2"
"@heroku-cli/command@npm:^11.2.2":
version: 11.2.2
resolution: "@heroku-cli/command@npm:11.2.2"
dependencies:
"@heroku-cli/color": ^2.0.1
"@oclif/core": ^2.16.0
Expand All @@ -1630,7 +1630,10 @@ __metadata:
netrc-parser: ^3.1.6
open: ^8.4.2
uuid: ^8.3.0
checksum: 93565c7177efa373b9f6120ed3d71bf739c09f5557f00c599d7f2cf4e8b6c42c552d314f31059d5f8d72e339c24919c2fe69bce31a2031ce35b6ff2f6db2f189
peerDependencies:
yargs-parser: ">=18.x"
yargs-unparser: ^2.0.0
checksum: 049415c4dad3eb116b50974c75c692905fa00bf0d25d0aff466d15ea18ee97f095fda78cc2d4da5921eb207ee5937c68de46006b63f4c6dc5ae3ebdffd58be03
languageName: node
linkType: hard

Expand Down Expand Up @@ -11204,7 +11207,7 @@ __metadata:
resolution: "heroku@workspace:packages/cli"
dependencies:
"@heroku-cli/color": 2.0.1
"@heroku-cli/command": ^11.1.2
"@heroku-cli/command": ^11.2.2
"@heroku-cli/notifications": ^1.2.4
"@heroku-cli/plugin-ps": ^8.1.7
"@heroku-cli/plugin-ps-exec": ^2.4.0
Expand Down

0 comments on commit bdeeb09

Please sign in to comment.