askio contains highly configurable and powerful command line interface tools. With the use ofaskiocreating interactive command-line tools becomes an ease. We've integrated beautiful UI's using theCallistapackage to integrate professional Cli's. askioonly philosophy is to help people maintain the professional attitude in the most easiest way.
Most of theaskiolibrary is based off of functions, although yes we have two modules that use classes because of their complex structural root.
The secret function is pretty useful when it comes to password prompting and full security of its getting leaked. A example with thesecret
function would be:
letaskio=require('askio');
letsecret=askio.Secret;//Note: no braces
(async()=>{
constvalue=awaitsecret({
message:"Enter your password.",
})
/*
This is a non-masked password i.e, no masks will be shown as well as the password being invisible.
*/
console.log("You sent",value)
/*
With a mask
*/
constanswer=awaitsecret({
message:"Enter your password.",
mask:'.'
})
console.log('You sent',`${answer}`)
})();
Options
name
,message
,maskWith
This module prompts for multiple option questions which can be moved about using the keyboard arrows, selected using thespacebar,all of them selected(or toggle all) with theakey and inverted using thei. Note: Not only can you use the keyboard arrows but also thewandskeys instead of up arrow and down arrow respectively An example of this module in use would be:
const{Check}=require('askio');
(async()=>{
constchoice=awaitCheck({
message:'What do you prefer?',
choices:[
{name:"Apple",
value:"apple"
},
{
name:"Orange",
value:"orange"
}// this can go on!
/*
,{
name: "Kiwi",
value: "kiwi",
disabled: true
}
this disables a package to be selected although shown!
*/
]
});
})();
options
name
,message
,choices
extend=> [{name, value, disabled(optional, checked(optional))}]
The checked option checks a choice by default which can not be overwritten.
Survey is a very intutive and interesting module which looks beautiful as well as breath-taking, with the help ofaskiosurvey creatings become a piece of cake.
An example of creating a survey withaskiowould be:
const{Survey}=require('askio');
constform=newSurvey({
name:'Movie Review',
message:'How\'d you like the movie?',
scale:[
{name:'1',message:'Coolish'},
{name:'2',message:'Dumbish'}
],
margin:[0,0,2,1],
choices:[
{
name:"Its theme",
value:"Its theme was okay, or bad?"
},
{
name:"Its fantasy?",
value:"did you like its fantasizing background?"
}
]
});
form.go()
.then(value=>console.log('ANSWERS:',value))
.catch(console.error);
options
name
,message
,scale
,margin
,choices
extends=> [{name, value}]
askioprovides an autocomplete module, which trys to understand an answer based upon user values.
An example would be:
const{AutoComplete}=require('askio');
constautocomp=newAutoComplete({
name:'color',
message:'Pick your favourite color',
limit:10,
initial:2,
choices:[
'Red',
'Green',
'blue',
'orange',
'magenta'
]
});
autocomp.go()
.then(answer=>
console.log('Fetched',answer))
.catch(console.error);
options
name
,message
,limit
,initial
,choices
,multiple
initial
specifies the number of already selected options
multiple
(default:
boolean
) specifies if there should be multiple choices.
Takes an input from the user
Example:
const{Input}=require('askio');
(async()=>{
constanswer=awaitInput({
message:"enter yer name"
})
console.log(answer+"was your name")
})();
options
message
,default
,validate
default
sets a default answer if no answer was provided.
validate
validates the answer.Returns a promise
Select out of a lot of options! Example:
constselect=require('askio');
(async()=>{
constanswer=awaitselect({
message:'Select your favorite letter',
choices:[
{value:"Dog",description:"An animal"},
{value:"Stuff toy",description:"Non-living"}
],
});
console.log('Answer:',answer);
})();
options
message
,choices
extends=> [{value, description}]
Expand to show the definitions of the options.
Example:
const{Expand}=require('askio');
const{Logger}=require("callista");
(async()=>{
constanswer=awaitExpand({
message:'Are you 18?',
default:'n',
choices:[
{
key:'n',
id:"No",
value:"No you aren't"
},
{
key:'y',
id:"Yes",
value:"Yes you are"
}
]
});
Logger.write(`You said${answer}`)
})();
Create placeholders for completing task, with an awesome percentage marker!
const{Snippet}=require('askio');
constquestion=newSnippet({
name:'username',
message:'Fill out the fields in package.json',
required:true,
fields:[
{
name:"Age",
value:"Enter your age"
},
{
name:"Name",
value:"Enter your name"
/*
,validate() { <- This is optional
}
*/
}
],
template:`{
"name": "\${name}",
"age": "\${age}"
}`
});
question.go()
.then(answer=>console.log('You said',answer.result))
.catch(console.error);
options
name
,message
,fields
extends-> [{name, value, validate(optional)}],template
template
-> Specifies the template in which the prompt should go on!
Although each library in this module already consists of incredible UI's as default we've also added user interfaceclassesjust for you!
Using the UI BottomBar is extremely easy, here's an example:
var{uiBottomBar}=require('askio');
varbar=newuiBottomBar;
bar.updateBottomBar('Lol');
// or as a simple logger
bar.log('haha')
This just provides a footer, at the bottom, like a text zone.
Well as the main motive of theaskiolibrary is to let developersaskquestions from the user via cli, we must provide a simple prompt library to provide flow.
You can ask questions using theAsk
class.
new askio.Ask(question, answer)