瀏覽代碼

Merge branch 'master' of http://git.bbh/chess/elxr

pull/6/head
chess 3 年之前
父節點
當前提交
6bd5d16e53
共有 2 個文件被更改,包括 51 次插入54 次删除
  1. 10
    4
      cliverse.js
  2. 41
    50
      index.js

+ 10
- 4
cliverse.js 查看文件

@@ -90,8 +90,9 @@ function nodeShellExec() {
var prompt = function(choices, label, defaultchoice){
var choices = choices || [];
return this.prompter.ask(
`${label} \n ` + Object.keys(choices).map(choice => { return ` ${(+choice) + 1}) ${choices[choice]} `}).join('\n') + `\n default ( <= ${ defaultchoice || choices[0]} ) : `
`${label} \n` + Object.keys(choices).map(choice => { return ` ${(+choice) + 1}) ${choices[choice]} `}).join('\n') + `\n default ( <= ${ defaultchoice || choices[0]} ) : `
).then(choice => {
// propName = promptable.interpret(propValue)
if(!choice) return defaultchoice || choices[0];
if(choice && isNaN(+choice)) return choice;
return choices[(+choice) - 1];
@@ -108,9 +109,14 @@ var cli = {
const clii = readline.createInterface({ input: process.stdin, output: process.stdout });
return new Promise((resolve, reject)=>{
clii.question(q, (answer)=>{
clii.close();
console.log("resolve is being called");
resolve(answer)
try {
clii.close();
console.log("readline.createInterface closed");
resolve(answer)
}
catch(e) {
reject(e)
}
})
})
}

+ 41
- 50
index.js 查看文件

@@ -2185,7 +2185,7 @@ var detectinstances = function () {

}

var __interactve_promts = function( selectedinstance ){
var __interactve_promts = function( target ){

return {
runchoice : {
@@ -2205,58 +2205,43 @@ var __interactve_promts = function( selectedinstance ){
, choices : []
, defaultchoice : 'c'
, interpret : function(choice){
var imap = {
var interpret_map = {
d : function(){
processedArgs._[0] = 'i'
selectedinstance.instanceName = processedArgs._[1] = processedArgs._[1] || 'chess'
selectedinstance.node_env = processedArgs.node_env = (process.env.NODE_ENV && process.env.NODE_ENV.trim()) || processedArgs.node_env || 'development'
selectedinstance.reposerver = 'https://git.bbh.org.in'
target.instanceName = processedArgs._[1] = processedArgs._[1] || 'chess'
target.node_env = processedArgs.node_env = (process.env.NODE_ENV && process.env.NODE_ENV.trim()) || processedArgs.node_env || 'development'
target.reposerver = 'https://git.bbh.org.in'
}
, n : function() { processedArgs._[0] = 'i' }
, i : function() { processedArgs._[0] = 'i' }
, c : function() { cli.prompter.ask(`Enter cmd :
p) pull
Default <= p
: `).then(function (cmd) {
if (!cmd || cmd === 'p') {
processedArgs._[0] = 'pull'
}
else processedArgs._[0] = cmd
return cmd;
})
, c : async function() {
Object.defineProperty(this, 'cmd', getPromptableAsyncPropDescriptor('cmd', {
label : `Enter cmd :
p) pull
Default <= p
: `
, defaultchoice : 'pull'
}
));

var cmd = await target['cmd'];
if (!cmd || cmd === 'p') { target['cmd'] = processedArgs._[0] = 'pull' }
else target['cmd'] = processedArgs._[0] = cmd
return cmd;
}
, h : function() { console.log(elxr.help()); process.exit() } // PB : TODO -- Why do we need log.
, q : function() { process.exit() }
}
if(!choice) return imap['c']
var __interpreter = interpret_map['c']
// if(!choice) return interpret_map['c']() // This should not happen prompter should always give us a default choice.
if(interpret_map[choice]) __interpreter = interpret_map[choice];
return imap[choice] ? imap[choice]() : imap['c'];
return __interpreter.call(target)
}
}
, instanceName : { label : `Enter Instance Name ( <= ${selectedinstance.instanceName} ) : `, choices : [], defaultchoice : 'chess'}
, instanceType : { label : `Enter Instance Type ( <= ${selectedinstance.instanceType} ) : `, choices : [], defaultchoice : 'development'}
, reposerver : { label : `Enter Instance Name ( <= ${selectedinstance.reposerver} ) : `, choices : [], defaultchoice : 'https://git.bbh.org.in'}
// get reposerver(){
// return cli.prompt(this.reposervers, 'git default repo').then(reposerver => {
// Object.defineProperty(this, 'reposerver', {
// value: reposerver,
// writable: false,
// configurable : true,
// enumerable : true
// });
// return reposerver
// })
// }
// , set reposerver(reposerver){
// Object.defineProperty(this, 'reposerver', {
// value: reposerver,
// writable: false,
// configurable : true,
// enumerable : true
// });
// return reposerver
// }
, instanceName : { label : `Enter Instance Name ( <= ${target.instanceName || 'chess'} ) : `, choices : [], defaultchoice : 'chess'}
, instanceType : { label : `Enter Instance Type ( <= ${target.instanceType || 'development'} ) : `, choices : [], defaultchoice : 'development'}
, reposerver : { label : `Enter Instance Name ( <= ${target.reposerver || 'https://git.bbh.org.in'} ) : `, choices : [], defaultchoice : 'https://git.bbh.org.in'}
}
}

@@ -2500,20 +2485,26 @@ var getPromptableAsyncPropDescriptor = function(propName, promptable){
return {
get (){
return cli.prompt( promptable.choices, promptable.label, promptable.defaultchoice ).then(propValue => {
propName = promptable.interpret(propValue)
Object.defineProperty(this, propName, {
value: propValue,
writable: false,
configurable : true,
enumerable : true
});
return propValue
if(promptable.interpret){
return propName = promptable.interpret(propValue).then(
()=>{
Object.defineProperty(this, propName, {
value: propValue,
writable: true,
configurable : true,
enumerable : true
});
return propValue
}
)
}
else return propValue
})
}
// , set (propValue){
// Object.defineProperty(this, propName, {
// value: propValue,
// writable: false,
// writable: true, // PB : TODO -- Use this to fix value permanently until run is over.
// configurable : true,
// enumerable : true
// })

Loading…
取消
儲存