Skip to content

Commit

Permalink
added default prompts support for cli
Browse files Browse the repository at this point in the history
  • Loading branch information
puntorigen committed Nov 6, 2022
1 parent 1ffcd4d commit addce3a
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 5 deletions.
78 changes: 78 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3225,6 +3225,84 @@
var copy = node;
delete copy.id;
return copy;
} // CONCEPTO_CLI helper methods


returnPromps() {
var _this23 = this;

return _asyncToGenerator(function* () {
require('prompts');

var prompts = {
ask: function () {
var _ask = _asyncToGenerator(function* (question) {
var validation = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
var resp = (yield prompts({
type: 'text',
name: 'value',
message: _this23.x_console.colorize(question),
validate: value => {
if (validation) return validation(value);
return true;
}
})).value;
return resp;
});

function ask(_x8) {
return _ask.apply(this, arguments);
}

return ask;
}(),
choose: function () {
var _choose = _asyncToGenerator(function* () {
var question = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
var selected = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
var resp = (yield prompts({
type: 'select',
name: 'value',
message: _this23.x_console.colorize(question),
choices: options,
initial: selected
})).value;
return resp;
});

function choose() {
return _choose.apply(this, arguments);
}

return choose;
}(),
multi: function () {
var _multi = _asyncToGenerator(function* () {
var question = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
var max = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
var hint = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
var resp = (yield prompts({
type: 'multiselect',
name: 'value',
message: _this23.x_console.colorize(question),
choices: options,
max,
hint: hint ? hint : '- Space to select. Return to submit'
})).value;
return resp;
});

function multi() {
return _multi.apply(this, arguments);
}

return multi;
}()
};
return prompts;
})();
}

} // private helper methods; not to be exported
Expand Down
49 changes: 47 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@concepto/interface",
"version": "2.1.996",
"version": "2.1.997",
"description": "Concepto DSL - visually create and maintain modern node.js based apps (@interface)",
"keywords": [
"creador",
Expand Down Expand Up @@ -29,17 +29,18 @@
"docs": "jsdoc2md -t README.hbs src/*.js > README.md"
},
"dependencies": {
"@concepto/console": "*",
"@concepto/dsl_parser": "*",
"await-spawn": "^4.0.2",
"cheerio": "*",
"deep-object-diff": "^1.1.0",
"deepmerge": "^4.2.2",
"@concepto/dsl_parser": "*",
"@concepto/console": "*",
"extractjs": "^0.3.1",
"humanize-duration": "^3.25.2",
"minimatch": "^3.0.4",
"node-persist": "^3.1.0",
"print-code": "^1.0.2",
"prompts": "^2.4.2",
"recursive-copy": "^2.0.11",
"safe-eval": "^0.4.1"
},
Expand Down
47 changes: 47 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2142,6 +2142,53 @@ export default class concepto {
return copy;
}

// CONCEPTO_CLI helper methods
async returnPromps() {
const prompts_ = require('prompts');
let prompts = {
ask: async(question,validation=null)=>{
const resp = (
await prompts({
type: 'text',
name: 'value',
message: this.x_console.colorize(question),
validate: (value) => {
if (validation) return validation(value);
return true
}
})
).value;
return resp;
},
choose: async(question='', options=[], selected=0) => {
const resp = (
await prompts({
type: 'select',
name: 'value',
message: this.x_console.colorize(question),
choices: options,
initial: selected
})
).value;
return resp;
},
multi: async(question='', options=[], max=0, hint=null) => {
const resp = (
await prompts({
type: 'multiselect',
name: 'value',
message: this.x_console.colorize(question),
choices: options,
max,
hint: (hint)?hint:'- Space to select. Return to submit'
})
).value;
return resp;
}
}
return prompts;
}

}

// private helper methods; not to be exported
Expand Down

0 comments on commit addce3a

Please sign in to comment.