<commit_before>var fs = require('fs')

fs.readdir('.', function(err, files) {
    if (err) {
        console.log(err)
    } else {
        files.forEach(function(file) {
            if (file.endsWith('.json')) {
                console.log(file);
                console.log(getDockerCommandLine(file))
                console.log()
            }
        });
    }
});

/**
 * If a environment variable value has one of this characters, it needs to be wrapped with double quotation
 */
function hasWrapChar(str) {
	var wrapChars = [' ', '&', ';'];
	for (var c in wrapChars)
		if (str.indexOf(wrapChars[c]) !== -1)
			return true;
	return false;
}

function getDockerCommandLine(fileName) {
    var dockerConfig = require('./' + fileName)[0];
    var command = 'docker run -d';
    command += ' --name=' + dockerConfig['Name'].substring(1);

    function getEnvs(dockerConfig) {
        var ret = '';

        var envs = dockerConfig['Config']['Env'];
        if (envs != null) {
            for (var i = 0; i < envs.length; i++) {
                var env = envs[i];
                if (!env.startsWith('PATH') && !env.startsWith('LANG') && !env.startsWith('LC_ALL')) {
                    ret += ' -e ';
                    if (hasWrapChar(env)) {
                        ret += env.substring(0, env.indexOf('=')) + '="' + env.substring(env.indexOf('=')+1) + '"';
                    } else {
                        ret += env;
                    }
                }
            }
        }

        return ret;
    }

    function getHostConfig(dockerConfig) {
        var ret = '';

        if (Object.keys(dockerConfig['HostConfig']['PortBindings']).length > 0) {
            for (var port in dockerConfig['HostConfig']['PortBindings']) {
                var bindings = dockerConfig['HostConfig']['PortBindings'][port];
                for (var i = 0; i < bindings.length; i++) {
                    ret += ' -p ' + bindings[i]['HostPort'] + ':' + port.split('/')[0];
                }
            }
        }

        if (dockerConfig['HostConfig']['Links'] != null) {
            var links = dockerConfig['HostConfig']['Links'];
            for (var i = 0; i < links.length; i++) {
                var link = links[i];
                var splitted = link.split('/');
                ret += ' --link ' + splitted[1] + splitted[3];
            }
        }

        return ret;
    }


    command += getEnvs(dockerConfig);
    command += getHostConfig(dockerConfig);

    command += ' ' + dockerConfig['Config']['Image'];

    return command;
}<commit_msg>Added identification of hostname and volume binding<commit_after>var fs = require('fs')

fs.readdir('.', function(err, files) {
    if (err) {
        console.log(err)
    } else {
        files.forEach(function(file) {
            if (file.endsWith('.json')) {
                console.log(file);
                console.log(getDockerCommandLine(file))
                console.log()
            }
        });
    }
});

/**
 * If a environment variable value has one of this characters, it needs to be wrapped with double quotation
 */
function hasWrapChar(str) {
	var wrapChars = [' ', '&', ';'];
	for (var c in wrapChars)
		if (str.indexOf(wrapChars[c]) !== -1)
			return true;
	return false;
}

function isHexaString(str) {
	return /^[A-Fa-f0-9]+$/.test(str);
}

function getDockerCommandLine(fileName) {
    var dockerConfig = require('./' + fileName)[0];
    var command = 'docker run -d';
    command += ' --name=' + dockerConfig['Name'].substring(1);

	if (!isHexaString(dockerConfig['Config']['Hostname'])) {
		command += ' --hostname=' + dockerConfig['Config']['Hostname'];
	}

    function getEnvs(dockerConfig) {
        var ret = '';

        var envs = dockerConfig['Config']['Env'];
        if (envs != null) {
            for (var i = 0; i < envs.length; i++) {
                var env = envs[i];
                if (!env.startsWith('PATH') && !env.startsWith('LANG') && !env.startsWith('LC_ALL')) {
                    ret += ' -e ';
                    if (hasWrapChar(env)) {
                        ret += env.substring(0, env.indexOf('=')) + '="' + env.substring(env.indexOf('=')+1) + '"';
                    } else {
                        ret += env;
                    }
                }
            }
        }

        return ret;
    }

    function getHostConfig(dockerConfig) {
        var ret = '';

        if (Object.keys(dockerConfig['HostConfig']['PortBindings']).length > 0) {
            for (var port in dockerConfig['HostConfig']['PortBindings']) {
                var bindings = dockerConfig['HostConfig']['PortBindings'][port];
                for (var i = 0; i < bindings.length; i++) {
                    ret += ' -p ' + bindings[i]['HostPort'] + ':' + port.split('/')[0];
                }
            }
        }

        if (dockerConfig['HostConfig']['Links'] != null) {
            var links = dockerConfig['HostConfig']['Links'];
            for (var i = 0; i < links.length; i++) {
                var link = links[i];
                var splitted = link.split('/');
                ret += ' --link ' + splitted[1].slice(0,-1);
				if (splitted[1].slice(0,-1) !== splitted[3]) {
					ret += ':' + splitted[3];
				}
            }
        }

		if (dockerConfig['HostConfig']['Binds'] != null) {
			var len = dockerConfig['HostConfig']['Binds'].length;
			for (var i = 0; i < len; i++) {
				var bind = dockerConfig['HostConfig']['Binds'][i];
				ret += ' -v ';
				if (hasWrapChar(bind)) bind = '"' + bind + '"';
				ret += bind;
			}
		}

        return ret;
    }


    command += getEnvs(dockerConfig);
    command += getHostConfig(dockerConfig);

    command += ' ' + dockerConfig['Config']['Image'];

    return command;
}
{'fraction_non_alphanumeric': 0.17334494773519163, 'fraction_numerical': 0.005749128919860627, 'mean_word_length': 1.8420792079207922, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2901489', 'n_tokens_mistral': 1816, 'n_tokens_neox': 1669, 'n_words': 363}