Architected
A tool for cli utilities.
About
Architected is a small wrapper around inquirer, listr and argi. It seamlessly manages arguments, user input and tasks.
Install
$ npm install --save architected
Usage
const architected = ; const config = // Configuration for architected config: name: 'my cli app' // The user input you want to receive. input: name: message: 'A short description' default: 'My default' type: 'input' // Cli commands commands: name: message: 'A short description' hidden: false
API
architected(config)
config
Configuration for architected.
name
Type: string
Required
The name of your project(will be used for --help
).
args
Type: array
Default: process.argv.slice(2)
Custom arguments. You should only change this if you have to.
commands
Commands passed as arguments.
Example:
Terminal:
my-app init
Code:
const architected = ; const config = config: name: 'my app' commands: init: message: 'Add readme.md file'
input
Input you want to receive.
name
Type: object
What the user input should be called. You need this to get the value of the user input.
-
message
Type:sting
A short description. It will be displayed in--help
and in the input prompt. -
default
Type: every
Will be used if the user does not specify a value. -
save
Type:boolean
If set totrue
the user input will be saved and will be suggested next time the user executes your cli utility. -
boolean
Type:boolean
Force input to be eithertrue
orfalse
.
Only for arguments. -
alias
Type:string
,array
Alternative name(eg. a short version).
Only for arguments. -
hidden
Type:boolean
Specify if the input should be displayed in--help
.
Only for arguments. -
type
Type:string
Type of the user input, can beinput
,confirm
,list
,rawlist
,expand
,checkbox
,password
,editor
.
Only for prompt.
Learn more -
choices
Type:array
,function
Choices for the user can only be used for certaintype
s.
Only for prompt.
Learn more -
validate
Type:function
Receives user input as the first argument. Should returntrue
if input is valid orfalse
if input is invalid.
Only for prompt. -
filter
Type:function
Receives user input as the first argument. Should return the filtered value.
Only for prompt. -
when
Type:function
Receives the previous user input as the first argument. Should returntrue
if the prompt can be displayed.
Only for prompt. -
pageSize
Type:number
The number of lines that will be rendered. Can only be used forlist
,rawList
,expand
orcheckbox
.
Only for prompt.
Returns
Type: promise
Will be called when all the user input is received and parsed.
ctx
Type: object
An object containing the user input.
Example:
... console; // Logs name input to the console....
add(name, [options], task)
Add a new task
Example:
... ; ;...
name
Type: string
The name of your task. Will be used for logging.
options
Type: object
Options for listr
. Learn more
task
Type: function
You should do your stuff here.
run([ctx])
Execute all tasks.
ctx
Type: object
Custom context. Will be Object.assign
ed to the user input.
Examples
Basic
A simple
package.json
generator.
#!/usr/bin/env node const writeFileSync mkdirSync = ;const join = ; const architected = ; ;
Observable
A simple node.js project boilerplate. Built using observables.
#!/usr/bin/env node const writeFileSync mkdirSync = ;const join = ; const Observable = ;const delay = ; // For a cool effect const architected = ; ;
License
MIT © Tobias Herber