#!/usr/bin/env node

var generateShader = function generateShader (args) {
    var ruleString = args[0] || null,
        outOfBoundValue = args[1] || 'wrap';

    outOfBoundValue = outOfBoundValue == 'wrap' || outOfBoundValue == 'clamp' ? outOfBoundValue : parseInt(outOfBoundValue, 10);

    console.log(generator(ruleString, outOfBoundValue));
};

var extractInformation = function extractInformation (content) {
    // not critical, dumb regular expressions will do
    var regexVersion = new RegExp('^/\\*\\*[\\S\\s]+cellular-automata-voxel-shader ([0-9.]+)[\\S\\s]+\\*/', 'mg'),
        regexRuleString = new RegExp('^/\\*\\*[\\S\\s]+Rule : (.+)[\\S\\s]+\\*/', 'mg'),
        regexOutOfBound = new RegExp('^/\\*\\*[\\S\\s]+Out of bound value : (.+)[\\S\\s]+\\*/', 'mg'),
        versionMatch = regexVersion.exec(content),
        ruleStringMatch = regexRuleString.exec(content),
        outOfBoundMatch = regexOutOfBound.exec(content);

    return {
        version : versionMatch ? versionMatch[1] : null,
        ruleString : ruleStringMatch ? ruleStringMatch[1] : null,
        outOfBoundValue : outOfBoundMatch ? outOfBoundMatch[1] : null,
        valid : versionMatch && ruleStringMatch && outOfBoundMatch
    };
};

var getInformation = function getInformation (args) {
    var fs = require('fs'),
        filename = args[1] || null,
        content,
        information;

    if (filename) {
        try {
            content = fs.readFileSync(filename).toString();
        } catch (e) {
            content = null;
        }

        information = extractInformation(content);

        if (information.valid) {
            console.log(filename + ' : ' + information.ruleString + ' : ' + information.outOfBoundValue + ' : generated by cavoxelshader ' + information.version);
        } else {
            console.log(filename + ' was not generated by cavoxelshader');
        }
    }
};

var generator = require('./../'),
    args = process.argv.slice(2);

if (args[0] === 'info') {
    getInformation(args);
} else {
    generateShader(args);
}

#!/usr/bin/env node

var generator = require('./../'),
    args = process.argv.slice(2),
    ruleString = args[0] || null,
    outOfBoundValue = args[1] || 'wrap';

outOfBoundValue = outOfBoundValue == 'wrap' || outOfBoundValue == 'clamp' ? outOfBoundValue : parseInt(outOfBoundValue, 10);

console.log(generator(ruleString, outOfBoundValue));

--- 
+++ 
@@ -1,10 +1,59 @@
 #!/usr/bin/env node
 
+var generateShader = function generateShader (args) {
+    var ruleString = args[0] || null,
+        outOfBoundValue = args[1] || 'wrap';
+
+    outOfBoundValue = outOfBoundValue == 'wrap' || outOfBoundValue == 'clamp' ? outOfBoundValue : parseInt(outOfBoundValue, 10);
+
+    console.log(generator(ruleString, outOfBoundValue));
+};
+
+var extractInformation = function extractInformation (content) {
+    // not critical, dumb regular expressions will do
+    var regexVersion = new RegExp('^/\\*\\*[\\S\\s]+cellular-automata-voxel-shader ([0-9.]+)[\\S\\s]+\\*/', 'mg'),
+        regexRuleString = new RegExp('^/\\*\\*[\\S\\s]+Rule : (.+)[\\S\\s]+\\*/', 'mg'),
+        regexOutOfBound = new RegExp('^/\\*\\*[\\S\\s]+Out of bound value : (.+)[\\S\\s]+\\*/', 'mg'),
+        versionMatch = regexVersion.exec(content),
+        ruleStringMatch = regexRuleString.exec(content),
+        outOfBoundMatch = regexOutOfBound.exec(content);
+
+    return {
+        version : versionMatch ? versionMatch[1] : null,
+        ruleString : ruleStringMatch ? ruleStringMatch[1] : null,
+        outOfBoundValue : outOfBoundMatch ? outOfBoundMatch[1] : null,
+        valid : versionMatch && ruleStringMatch && outOfBoundMatch
+    };
+};
+
+var getInformation = function getInformation (args) {
+    var fs = require('fs'),
+        filename = args[1] || null,
+        content,
+        information;
+
+    if (filename) {
+        try {
+            content = fs.readFileSync(filename).toString();
+        } catch (e) {
+            content = null;
+        }
+
+        information = extractInformation(content);
+
+        if (information.valid) {
+            console.log(filename + ' : ' + information.ruleString + ' : ' + information.outOfBoundValue + ' : generated by cavoxelshader ' + information.version);
+        } else {
+            console.log(filename + ' was not generated by cavoxelshader');
+        }
+    }
+};
+
 var generator = require('./../'),
-    args = process.argv.slice(2),
-    ruleString = args[0] || null,
-    outOfBoundValue = args[1] || 'wrap';
+    args = process.argv.slice(2);
 
-outOfBoundValue = outOfBoundValue == 'wrap' || outOfBoundValue == 'clamp' ? outOfBoundValue : parseInt(outOfBoundValue, 10);
-
-console.log(generator(ruleString, outOfBoundValue));
+if (args[0] === 'info') {
+    getInformation(args);
+} else {
+    generateShader(args);
+}
Add 'info' command to extract the information from a generated voxel shader
