Browse Source

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

pull/6/head
chess 3 years ago
parent
commit
6bd5d16e53
2 changed files with 51 additions and 54 deletions
  1. 10
    4
      cliverse.js
  2. 41
    50
      index.js

+ 10
- 4
cliverse.js View File

var prompt = function(choices, label, defaultchoice){ var prompt = function(choices, label, defaultchoice){
var choices = choices || []; var choices = choices || [];
return this.prompter.ask( 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 => { ).then(choice => {
// propName = promptable.interpret(propValue)
if(!choice) return defaultchoice || choices[0]; if(!choice) return defaultchoice || choices[0];
if(choice && isNaN(+choice)) return choice; if(choice && isNaN(+choice)) return choice;
return choices[(+choice) - 1]; return choices[(+choice) - 1];
const clii = readline.createInterface({ input: process.stdin, output: process.stdout }); const clii = readline.createInterface({ input: process.stdin, output: process.stdout });
return new Promise((resolve, reject)=>{ return new Promise((resolve, reject)=>{
clii.question(q, (answer)=>{ 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 View File



} }


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


return { return {
runchoice : { runchoice : {
, choices : [] , choices : []
, defaultchoice : 'c' , defaultchoice : 'c'
, interpret : function(choice){ , interpret : function(choice){
var imap = {
var interpret_map = {
d : function(){ d : function(){
processedArgs._[0] = 'i' 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' } , n : function() { processedArgs._[0] = 'i' }
, i : 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. , h : function() { console.log(elxr.help()); process.exit() } // PB : TODO -- Why do we need log.
, q : function() { process.exit() } , 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'}
} }
} }


return { return {
get (){ get (){
return cli.prompt( promptable.choices, promptable.label, promptable.defaultchoice ).then(propValue => { 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){ // , set (propValue){
// Object.defineProperty(this, propName, { // Object.defineProperty(this, propName, {
// value: propValue, // value: propValue,
// writable: false,
// writable: true, // PB : TODO -- Use this to fix value permanently until run is over.
// configurable : true, // configurable : true,
// enumerable : true // enumerable : true
// }) // })

Loading…
Cancel
Save