'use strict';

var express = require('express');
var node_path = require('path');
var fs = require('fs-sync');

var parser = require('argv-parser');

module.exports = {
    route: '/_action/:action',
    callback: function (req, res, next) {
        var action = req.params.action;
        var options = req.query;
        var parsed;

        var option_file = node_path.resolve(__dirname, '..', 'option', action + '.js');
        var command_file = node_path.resolve(__dirname, '..', 'command', action + '.js');

        if(fs.exists(option_file)){
            var option_rules = require(option_file).options;
            parsed = parser.clean(options, {
                rules: option_rules
            });
        }

        if(parsed.err){
            return res.send(500, {
                error: parsed.errors
            });
        
        }else{
            options = parsed.parsed;
        }

        if(!fs.exists(command_file)){
            return res.send(500, {
                error: 'Action "' + action + '" not found.'
            });
        }

        var commander = require(command_file);

        commander(options, function (err, data) {
            if(err){
                res.send(500, {
                    error: err.message || err
                });

            }else{
                res.send(200, {
                    message: data || 'ok'
                });
            }
        });
    },

    method: 'get',

    open: function (root) {
        require('child_process').exec('open ' + root + '/_action/build?cwd=/Users/Kael/Codes/F2EI/neurons/asset');
    }
};
@@ -141,16 +141,57 @@
 arser');
+%0Avar commander = require('../commander');
 %0A%0Amodule
@@ -474,85 +474,208 @@
 var 
-command_fi
+action_hand
 le
+r
  = 
-node_path.resolve(__dirname, '..', 'command', action + '.js');
+commander.get_commander(action);%0A%0A        if(!action_handler)%7B%0A            return res.send(500, %7B%0A                error: 'Action %22' + action + '%22 not found.'%0A            %7D);%0A        %7D
 %0A%0A  
@@ -1073,225 +1073,26 @@
     
-if(!fs.exists(command_file))%7B%0A            return res.send(500, %7B%0A                error: 'Action %22' + action + '%22 not found.'%0A            %7D);%0A        %7D%0A%0A        var commander = require(command_file);%0A%0A        commander
+action_handler.run
 (opt

use comfort to execute commander instead