UNPKG

1.88 kBJavaScriptView Raw
1'use strict';
2
3const child = require('child_process');
4const cli = require('heroku-cli-util');
5const exec = require('heroku-exec-util');
6const co = require('co');
7const Client = require('ssh2').Client;
8const https = require('https')
9const url = require('url');
10const tty = require('tty');
11const path = require('path');
12const fs = require('fs');
13const stream = require('stream');
14
15module.exports = function(topic, command) {
16 return {
17 topic: topic,
18 command: command,
19 description: 'Copy a file from a dyno to the local filesystem',
20 help: `Example:
21
22 $ heroku ps:copy FILENAME --app murmuring-headland-14719`,
23 args: [ {name: 'file'} ],
24 flags: [
25 { name: 'dyno', char: 'd', hasValue: true, description: 'specify the dyno to connect to' },
26 { name: 'output', char: 'o', hasValue: true, description: 'the name of the output file' }],
27 needsApp: true,
28 needsAuth: true,
29 run: cli.command(co.wrap(run))
30 }
31};
32
33function * run(context, heroku) {
34 var src = context.args.file
35 var dest = context.flags.output ? context.flags.output : path.basename(src)
36
37 cli.log(`Copying ${cli.color.white.bold(src)} to ${cli.color.white.bold(dest)}`)
38 if (fs.existsSync(dest)) {
39 cli.error(`The local file ${cli.color.white.bold(dest)} already exists!`)
40 } else {
41 yield exec.initFeature(context, heroku, function *(configVars) {
42 yield exec.updateClientKey(context, heroku, configVars, function(privateKey, dyno, response) {
43 var message = `Connecting to ${cli.color.cyan.bold(dyno)} on ${cli.color.app(context.app)}`
44 cli.action(message, {success: false}, co(function* () {
45 cli.hush(response.body);
46 var json = JSON.parse(response.body);
47 exec.scp(context, json['tunnel_host'], json['client_user'], privateKey, src, dest)
48 }))
49 })
50 });
51 }
52 return new Promise(resolve => {})
53}