Skip to content

Commit

Permalink
Fix(run): arguments are incorrectly gathered leading to duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
justinwilaby committed Aug 30, 2024
1 parent 2aa043a commit b39a726
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions packages/cli/src/commands/local/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {FileCompletion} from '@heroku-cli/command/lib/completions'
import {Command, Flags} from '@oclif/core'
import color from '@heroku-cli/color'
import {fork as foreman} from '../../lib/local/fork-foreman'
import {revertSortedArgs} from '../../lib/run/helpers'
import * as fs from 'fs'

export default class Run extends Command {
Expand All @@ -27,9 +26,10 @@ export default class Run extends Command {
async run() {
const execArgv: string[] = ['run']
const {argv, flags} = await this.parse(Run)
const userArgvInputOrder = revertSortedArgs(process.argv, argv as string[])
const maybeOptionsIndex = process.argv.indexOf('--')
const commandArgs = (maybeOptionsIndex === -1 ? argv : process.argv.slice(maybeOptionsIndex + 1)) as string[]

if (userArgvInputOrder.length === 0) {
if (commandArgs.length === 0) {
const errorMessage = 'Usage: heroku local:run [COMMAND]\nMust specify command to run'
this.error(errorMessage, {exit: -1})
}
Expand All @@ -44,7 +44,7 @@ export default class Run extends Command {
if (flags.port) execArgv.push('--port', flags.port)

execArgv.push('--') // disable node-foreman flag parsing
execArgv.push(...userArgvInputOrder as string[]) // eslint-disable-line unicorn/no-array-push-push
execArgv.push(...commandArgs as string[]) // eslint-disable-line unicorn/no-array-push-push

await foreman(execArgv)
}
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/src/commands/run/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {ux} from '@oclif/core'
import debugFactory from 'debug'
import * as Heroku from '@heroku-cli/schema'
import Dyno from '../../lib/run/dyno'
import {buildCommand, revertSortedArgs} from '../../lib/run/helpers'
import {buildCommand} from '../../lib/run/helpers'

const debug = debugFactory('heroku:run')

Expand Down Expand Up @@ -33,14 +33,14 @@ export default class Run extends Command {

async run() {
const {argv, flags} = await this.parse(Run)
const userArgvInputOrder = revertSortedArgs(process.argv, argv as string[])

const maybeOptionsIndex = process.argv.indexOf('--')
const command = buildCommand((maybeOptionsIndex === -1 ? argv : process.argv.slice(maybeOptionsIndex + 1)) as string[])
const opts = {
'exit-code': flags['exit-code'],
'no-tty': flags['no-tty'],
app: flags.app,
attach: true,
command: buildCommand(userArgvInputOrder as string[]),
command,
env: flags.env,
heroku: this.heroku,
listen: flags.listen,
Expand Down

0 comments on commit b39a726

Please sign in to comment.