Permalink
Browse files

初步实现edit功能

  • Loading branch information...
1 parent d627022 commit 20f6864acfdbea011183780c3bc0189a21158ea3 jicheng.li committed May 7, 2012
Showing with 23 additions and 0 deletions.
  1. +17 −0 fun/commandline.js
  2. +6 −0 fun/settings.js
View
@@ -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;
@@ -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
View
@@ -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.