"use strict";
var fs = require( 'fs' );
var readlineSync = require( '@fsteam/readline-sync' );

var conf = require( "../../config/build.config" );
var obj = {};

obj.select_cmd = function( list, msg ) {
	var cmd = [];
	for ( var i = 0; i < list.length; i++ ) {
		cmd.push( list[ i ].info );
	}
	var key = readlineSync.keyInSelect( cmd, msg || "请输入您想要进行的操作：" );

	return list[ key ].cmd;
};

obj.getName = function( msg ) {
	msg = msg || "请输入内容："；
	var name = readlineSync.question( msg );
	while( name === "" ) {
		if ( readlineSync.question( "您输入的内容为空！是否重新输入?（y/n）" ) === "y" ) {
			name = readlineSync.question( msg );
		} else {
			break;
		}
	}
	
	return name;
};

obj.is_project_dir = function( hoofile ) {
	hoofile = hoofile || __dirname + "/" + conf.hoofile;
	if ( fs.existsSync( hoofile ) ) {
		return require( hoofile );
	} else {
		return false;
	}
};

exports.obj = obj;