var constants = require('./constants');

var containerCommands = {
    cdHome: 'cd ' + constants.testContainerHome,
    cpIndex: 'cp -f test/image/index.html ../server_app/index.html',
    restart: 'supervisorctl restart nw1',
};

containerCommands.ping = [
    'wget',
    '--server-response --spider --tries=10 --retry-connrefused',
    constants.testContainerUrl + 'ping'
].join(' ');

containerCommands.setup = [
    containerCommands.cpIndex,
    containerCommands.restart,
    containerCommands.ping,
    'echo '
].join(' && ');

containerCommands.runLocal = function(commands) {
    commands = [containerCommands.cdHome].concat(commands);

    return [
        'docker exec -i',
        constants.testContainerName,
        '/bin/bash -c',
        '"' + commands.join(' && ') + '"'
    ].join(' ');
};

containerCommands.runCI = function(commands) {
    commands = ['export CIRCLECI=1', containerCommands.cdHome].concat(commands);

    return [
        'lxc-attach -n',
        '$(docker inspect --format \'{{.Id}}\'' + constants.testContainerName + ')',
        '-- bash -c',
        commands.join(' && ')
    ].join(' ');
};

module.exports = containerCommands;

@@ -525,24 +525,25 @@
 n(' && ');%0A%0A
+%0A
 containerCom
@@ -552,27 +552,321 @@
 nds.
-runLocal = function
+getRunCmd = function(commands, isCI) %7B%0A    var _commands = Array.isArray(commands) ? commands.slice() : %5Bcommands%5D;%0A%0A    if(isCI) return getRunCI(_commands);%0A%0A    // add setup commands locally%0A    _commands = %5BcontainerCommands.setup%5D.concat(_commands);%0A    return getRunLocal(_commands);%0A%7D;%0A%0Afunction getRunLocal
 (com
@@ -1099,45 +1099,27 @@
 );%0A%7D
-;
 %0A%0A
-containerCommands.runCI = function
+function getRunCI
 (com
@@ -1402,17 +1402,16 @@
 (' ');%0A%7D
-;
 %0A%0Amodule

merge CI vs local run cmd logic in container command module