1 | 'use strict'
|
2 |
|
3 | let cli = require('heroku-cli-util')
|
4 | let helpers = require('../lib/helpers')
|
5 | let Dyno = require('../lib/dyno')
|
6 | const { DynoSizeCompletion, ProcessTypeCompletion } = require('@heroku-cli/command/lib/completions')
|
7 | const debug = require('debug')('heroku:run')
|
8 |
|
9 | async function run (context, heroku) {
|
10 | let opts = {
|
11 | heroku: heroku,
|
12 | app: context.app,
|
13 | command: helpers.buildCommand(context.args),
|
14 | size: context.flags.size,
|
15 | type: context.flags.type,
|
16 | notify: !context.flags['no-notify'],
|
17 | 'exit-code': context.flags['exit-code'],
|
18 | env: context.flags.env,
|
19 | 'no-tty': context.flags['no-tty'],
|
20 | attach: true,
|
21 | listen: context.flags.listen
|
22 | }
|
23 | if (!opts.command) throw new Error('Usage: heroku run COMMAND\n\nExample: heroku run bash')
|
24 |
|
25 | let dyno = new Dyno(opts)
|
26 | try {
|
27 | await dyno.start()
|
28 | debug('done running')
|
29 | } catch (err) {
|
30 | debug(err)
|
31 | if (err.exitCode) cli.exit(err.exitCode, err)
|
32 | else throw err
|
33 | }
|
34 | }
|
35 |
|
36 | module.exports = {
|
37 | topic: 'run',
|
38 | description: 'run a one-off process inside a heroku dyno',
|
39 | help: 'Shows a notification if the dyno takes more than 20 seconds to start.',
|
40 | examples: `$ heroku run bash
|
41 | Running bash on app.... up, run.1
|
42 | ~ $
|
43 |
|
44 | $ heroku run -s hobby -- myscript.sh -a arg1 -s arg2
|
45 | Running myscript.sh -a arg1 -s arg2 on app.... up, run.1`,
|
46 | variableArgs: true,
|
47 | needsAuth: true,
|
48 | needsApp: true,
|
49 | flags: [
|
50 | { name: 'size', char: 's', description: 'dyno size', hasValue: true, completion: DynoSizeCompletion },
|
51 | { name: 'type', description: 'process type', hasValue: true, completion: ProcessTypeCompletion },
|
52 | { name: 'exit-code', char: 'x', description: 'passthrough the exit code of the remote command' },
|
53 | { name: 'env', char: 'e', description: "environment variables to set (use ';' to split multiple vars)", hasValue: true },
|
54 | { name: 'no-tty', description: 'force the command to not run in a tty', hasValue: false },
|
55 | { name: 'listen', description: 'listen on a local port', hasValue: false, hidden: true },
|
56 | { name: 'no-notify', description: 'disables notification when dyno is up (alternatively use HEROKU_NOTIFICATIONS=0)', hasValue: false }
|
57 | ],
|
58 | run: cli.command(run)
|
59 | }
|