var libs = require("./normal_libs.js");



getArgv = function(){
    var arr = process.argv.slice(2);

    var args = [];
    var i = 1, li = arr.length;
    for(; i < li; i++){
        var itemi = arr[i];
        if(itemi.search(/-(\w*)/) == 0) break;
        args.push(itemi);
    }

    var opts = {};
    var values4Opt = [];
    var name = null;
    for(; i < li; i++){
        var itemi = arr[i];
        if(itemi.search(/-(\w*)/) == 0){
            if(!name) name = itemi;
            else{
                opts[name] = values4Opt;
                name = itemi;
                values4Opt = [];
            }
        }else{
            values4Opt.push(itemi);
        }
    }

    if(name) opts[name] = values4Opt;

    var result = {
        name : arr[0],
        currDir : process.cwd(),
        args : args,
        opts : opts
    }

    return result;
};

function _getEnv(){
    return process.env;
}

function getOption(option,key,enumList){
    if (!option[key]){
        return enumList[0];
    }

    var value = option[key][0]
    if (!value || enumList.indexOf(value) == -1){
        libs.exit(8001,key,enumList);
    }
    return value;
}


exports.getEnv = _getEnv;

exports.getEgretPath = function(){
    var path = require("path");
    var obj = _getEnv();
    var egret_path = _getEnv().EGRET_PATH;
    if (!egret_path){
        egret_path = path.join(process.argv[1],"../../../");
    }
    return egret_path;
}




exports.getArgv = getArgv;

exports.getOption = getOption;
@@ -33,16 +33,67 @@
 s.js%22);%0A
+var fs = require(%22fs%22);%0Avar path = require(%22path%22);
 %0A%0A%0AgetAr
@@ -97,34 +97,36 @@
 tArgv = function
+ 
 ()
+ 
 %7B%0A    var arr = 
@@ -199,32 +199,33 @@
 .length;%0A    for
+ 
 (; i %3C li; i++)%7B
@@ -215,32 +215,33 @@
  (; i %3C li; i++)
+ 
 %7B%0A        var it
@@ -256,32 +256,33 @@
 r%5Bi%5D;%0A        if
+ 
 (itemi.search(/-
@@ -407,16 +407,17 @@
 %0A    for
+ 
 (; i %3C l
@@ -423,16 +423,17 @@
 li; i++)
+ 
 %7B%0A      
@@ -464,16 +464,17 @@
       if
+ 
 (itemi.s
@@ -494,16 +494,17 @@
 /) == 0)
+ 
 %7B%0A      
@@ -511,16 +511,17 @@
       if
+ 
 (!name) 
@@ -546,24 +546,25 @@
         else
+ 
 %7B%0A          
@@ -680,20 +680,22 @@
        %7D
+ 
 else
+ 
 %7B%0A      
@@ -747,16 +747,17 @@
 %0A%0A    if
+ 
 (name) o
@@ -812,17 +812,16 @@
     name
- 
 : arr%5B0%5D
@@ -837,17 +837,16 @@
  currDir
- 
 : proces
@@ -866,17 +866,16 @@
     args
- 
 : args,%0A
@@ -886,17 +886,16 @@
     opts
- 
 : opts%0A 
@@ -941,16 +941,17 @@
 getEnv()
+ 
 %7B%0A    re
@@ -997,20 +997,22 @@
 (option,
+ 
 key,
+ 
 enumList
@@ -1012,16 +1012,17 @@
 numList)
+ 
 %7B%0A    if
@@ -1036,16 +1036,17 @@
 on%5Bkey%5D)
+ 
 %7B%0A      
@@ -1153,16 +1153,17 @@
 ) == -1)
+ 
 %7B%0A      
@@ -1179,20 +1179,22 @@
 it(8001,
+ 
 key,
+ 
 enumList
@@ -1247,24 +1247,65 @@
 = _getEnv;%0A%0A
+%0A/**%0A * %E8%8E%B7%E5%8F%96egret%E6%89%80%E5%9C%A8%E7%9A%84%E4%BD%8D%E7%BD%AE%0A * @returns %7B*%7D%0A */%0A
 exports.getE
@@ -1323,18 +1323,20 @@
 function
+ 
 ()
+ 
 %7B%0A    va
@@ -1449,16 +1449,17 @@
 et_path)
+ 
 %7B%0A      
@@ -1464,59 +1464,620 @@
     
-egret_path = path.join(process.argv%5B1%5D,%22../../../%22)
+var globalpath = module.paths.concat();%0A        var existsFlag = false;%0A        for (var i = 0; i %3C globalpath.length; i++) %7B%0A            var prefix = globalpath%5Bi%5D;%0A            var url = path.join(prefix, %22egret%22);%0A            if (fs.existsSync(url)) %7B%0A                existsFlag = true;%0A                break;%0A            %7D%0A            var url = path.join(prefix, %22../egret%22);%0A            if (fs.existsSync(url)) %7B%0A                existsFlag = true;%0A                break;%0A            %7D%0A%0A        %7D%0A        if (!existsFlag) %7B%0A            throw new Error(%22can't find Egret%22);%0A        %7D%0A%0A%0A        egret_path = url
 ;%0A  
@@ -2107,18 +2107,16 @@
 th;%0A%7D%0A%0A%0A
-%0A%0A
 exports.

解决如果不设置环境变量，egret地址获取错误的bug