command.sytaxTree(object) // define the syntax of your commands
sytaxTree Object:
Command : nested object with the name of commands
$ARGS:[object,...]:define the lists of arguments
name * : a String define the variable name
required: a Boolean define if he argument is required or not
alias: an array of alias of the variable name prefixed by [-] exemple:[-o,-output]
type:sting define the variable type exemple [string, number,...]
label:string describe the variable shown in error message like if you have variable userName the label should be user_name if omited it will be generated from the variable name
$FN:the function to execute
$FLAGS:array of flag send to the function exemple : [-force,-f]
Add Type
command.addType(type_name,callback) : return a boolean
terminal.prompt (object) you can directly change the prompt
prefix exemple : terminal.prompt.prefix="quot;
root exemple : terminal.prompt.prefix="myshell"
postfix exemple : terminal.prompt.prefix=">"
styles exemple : terminal.prompt.styles=['blue','bold'] //this use chalk to style the prompt see style section you can use color bgcolor an modifier function
terminal.clearPrompt() clear the pushed elements in the prompt terminal.setPrompt(array) terminal.popPrompt()\
terminal.getPrompt() return the prompt as an array terminal.run(prompt,callback)
prompt object:
prefix
root
postfix
styles
callback a function called after closing the terminal this may be to show a message a do some extra work
exemple :
const {terminal,setStyle}=require("smart-cmd")
terminal.pushPrompt("/hello")
terminal.popPrompt()
terminal.run({prefix:"quot;,root:"myShell",postfix:">",styles:['blue']},function(){
console.log(setStyle("Quit",["red"]))
})// this callback prin Quit with red color when closing the terminal
Examples with required arguments
if you forget to pass the required argument an error message is shown see previous example
Examples with optional arguments
if required is omitted or equal to false the arguments is optional
Examples pass null to optional arguments
const {command}=require("smart-cmd")
command.syntaxTree({
convert:{
$ARGS:[{name:"input",required:true},{name:"format"},{name:"output",required:true}],
$FN({input,format,output}){
console.log({input,format,output})
//your code to conver video ....
}
}
})
command.run()
run node app convert movie.avi [null] movie.mp4
Examples with alias
you can rewrite the previous example with alias .alias is more flexible you can pass arguments in the order you want it like key value objects