Skip to content

Commit

Permalink
初步实现edit功能
Browse files Browse the repository at this point in the history
  • Loading branch information
jicheng.li committed May 7, 2012
1 parent d627022 commit 20f6864
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
17 changes: 17 additions & 0 deletions fun/commandline.js
Expand Up @@ -4,6 +4,7 @@
*/
var shell = require('../lib/shell.js');
var env = require('./settings.js');
var exec = require('child_process').exec;

//由app.js传进来的proxy实例
var proxy;
Expand Down Expand Up @@ -143,6 +144,22 @@ shell.command('down', function(args, next){
next('groups');
});
}, auto_groups);
//编辑某个分组,用默认编辑器打开对应的rule文件
shell.command('edit', function(args, next){
if(!args.length){ //必须指定分组名
shell.print( '必须指定分组名' );
next();
return;
}
if(!env.config.editor){
shell.print( '配置文件中没有指定editor' );
next();
return;
}
//调用默认编辑器
var cmdStr = env.config.editor +' '+ env.getRpath( args[0] ); //editor /path/to/.rule
exec(cmdStr, {cwd: env.paths.conf}); //在配置目录下执行编辑命令
}, auto_groups);
//查看规则列表
shell.command('ls', function(args, next){
//处理参数args
Expand Down
6 changes: 6 additions & 0 deletions fun/settings.js
Expand Up @@ -89,9 +89,15 @@ if(cfilepath){
config = readConfigFile(cfilepath);
//用命令行参数覆盖configfile的设置
if( options.port ) config.port = options.port;
if( options.editor ) config.editor = options.editor;
}
paths.configfile = cfilepath;

//用分组名字拼出该.rule文件的完整路径
exports.getRpath = function( groupname ){
return paths.rule +'/'+ groupname +'.rule';
};

exports.config = config;
exports.paths = paths; //统一文件路径变量
//console.log( config, paths);

0 comments on commit 20f6864

Please sign in to comment.