Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cli-form

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cli-form - npm Package Compare versions

Comparing version 0.0.1 to 0.1.0

lib/form.js

5

example.js

@@ -6,4 +6,5 @@ var NewForm = require('./');

{ key: "workspace", title: "Where do you keep your code?", default: process.cwd(), forOnce: true },
{ key: "name", title: "What's your new project name?", validate: { len: [1], name: "Project Name" } },
{ title: "Starter", desc: "user/repo (Github) or a full Git URL to clone.", default: "bud/react-starter" }
{ key: "name", title: "What's your new project name?", expect: { len: [1], name: "Project Name" } },
{ title: "Starter", desc: "user/repo (Github) or a full Git URL to clone.", default: "bud/react-starter" },
{ title: "Github Repo?", default: "{github}/{name}" }
]);

@@ -10,0 +11,0 @@

72

index.js

@@ -1,71 +0,1 @@

var struct = require("new-struct");
var NewDoc = require("config-doc");
var QA = require("cli-qa");
var format = require("format-text");
var Form = struct({
ask: ask,
questions: questions,
isMissingQuestion: isMissingQuestion,
formatQuestion: formatQuestion,
rememberLastAnswer: rememberLastAnswer
});
module.exports = NewForm;
function NewForm (filename, options) {
return Form({
content: NewDoc(filename),
options: options
});
}
function ask (form, callback) {
QA(form.questions(), function (answers) {
var key;
for (key in answers) {
form.content.set(key, answers[key]);
}
callback(form.content.document);
});
}
function questions (form) {
var result = form.options
.map(QA.normalizeQuestion)
.filter(form.isMissingQuestion);
result.forEach(form.rememberLastAnswer);
result.forEach(form.formatQuestion);
return result;
}
function isMissingQuestion (form, question) {
return !question.forOnce || form.content.get(question.key) === undefined;
}
function formatQuestion (form, question) {
var desc = question.desc || question.description || '';
var defaultValue = '';
if (question.default) {
defaultValue = format(' (Default: {0})', question.default);
}
if (desc) {
desc = format(' {0} ', desc);
}
question.title = format("\n {bold}{white}{0}{reset}{1}{2}\n {reset}{bold}{white}> {reset}", question.title, desc, defaultValue);
}
function rememberLastAnswer (form, question) {
var last = form.content.get(question.key);
if (question.default || !last) return;
question.default = last;
}
module.exports = require('./lib/form');
{
"name": "cli-form",
"version": "0.0.1",
"version": "0.1.0",
"description": "Build user-friendly command-line forms",

@@ -21,3 +21,3 @@ "main": "index.js",

"dependencies": {
"cli-qa": "^1.0.0",
"cli-qa": "^2.1.0",
"config-doc": "^0.1.0",

@@ -24,0 +24,0 @@ "format-text": "0.0.3",

@@ -21,4 +21,5 @@ ## cli-form

{ key: "workspace", title: "Where do you keep your code?", default: process.cwd(), forOnce: true },
{ key: "name", title: "What's your new project name?", validate: { len: [1] } },
{ title: "Starter", desc: "user/repo (Github) or a full Git URL to clone.", default: "bud/react-starter" }
{ key: "name", title: "What's your new project name?", expect: { len: [1] } },
{ title: "Starter", desc: "user/repo (Github) or a full Git URL to clone.", default: "bud/react-starter" },
{ title: "Github Repo?", default: "{github}/{name}" }
])

@@ -39,2 +40,5 @@

cli-form is a wrapper for [cli-qa](http://github.com/azer/cli-qa) module, formatted by default with a description option. [Reference](https://github.com/azer/cli-qa#reference)
cli-form is a wrapper for [cli-qa](http://github.com/azer/cli-qa) module. In addition to what cli-qa's [Reference](https://github.com/azer/cli-qa#reference) lists;
* desc
* forOnce
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc