123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
-
-
-
- function isWin(){ return /^win/.test(process.platform) }
- try {
-
- if(isWin()) {
- var win_verse = require('./win_verse')
- var shell_verse = win_verse;
- }
- else {
- var lin_verse = require('./lin_verse')
- var shell_verse = lin_verse;
- }
- }
- catch(e) {
- console.dir(e);
- console.error('cli environment detection failed')
- }
-
- const BUILD_VERSION = '[VI]Version: {version} - built on {date}[/VI]';
- shell_verse.getVersion = function getVersion() { return BUILD_VERSION; }
-
-
-
- console.log('----------------------')
-
- console.log('----------------------')
-
-
- const fs = require('fs')
-
- var {nodeShellExec, createTask} = require('./nodeshell')
-
- var prompt = function(choices, label, defaultchoice, selectedchoice){
-
- var choices = choices || [];
- defaultchoice = defaultchoice || choices[0] || selectedchoice || choices[Object.keys(choices)[0]]
- var ci = 0;
- return this.prompter.ask(
- `${label} \n` + Object.keys(choices).map(
- choice => {
- ++ci; var choice_label = isNaN(+choice) ? `${ci}) (${choice})` : ci + ')';
- return ` ${choice_label} ${choices[choice]} `
- }).join('\n')
- + `\n d) default ( <= ${ defaultchoice || choices[0]} ) : `
- + `\n selected ( <= ${ selectedchoice || defaultchoice || choices[0]} ) : `
- ).then(choice => {
-
- if(!choice && selectedchoice) return selectedchoice;
- if(!choice) return defaultchoice || choices[0];
- if(choice && isNaN(+choice)) {
- if(choice === 'd') return defaultchoice || choices[0];
- try {
- return JSON.parse(choice);
- }
- catch(e) {
-
- return choice
- }
- }
- return choices[(+choice) - 1];
- })
- }
-
- const readline = require("readline");
- var cli = {
- nodeShellExec
- , get prompter() {
- var prompt_interface = {
- ask : function(q){
-
- const clii = readline.createInterface({ input: process.stdin, output: process.stdout });
- return new Promise((resolve, reject)=>{
- clii.question(q, (answer)=>{
- console.log(answer)
- try {
- clii.close();
- console.log("readline.createInterface closed");
- resolve(answer)
- }
- catch(e) {
- reject(e)
- }
- })
- })
- }
- }
- return prompt_interface
- }
- , prompt
- , createTask
- , shell_verse : shell_verse
- }
-
- module.exports = cli
|