3.1.2 • Published 6 years ago
cliy v3.1.2
Cliy
Command Line Interface Library. example
Features
- Configuration based API
- Auto created help menus
Example
#!/usr/bin/env node
const Cliy = require('./index');
const Package = require('./package');
(async function() {
const program = new Cliy();
await program.setup({
name: Package.name,
version: Package.version,
operations: [
{
key: 'a',
name: 'one',
description: 'I am an Operation',
options: [
'opt1',
{ name: 'opt2', description: 'I am an Option' },
],
async handler (options, results, parameters) {
console.log(`a options: ${JSON.stringify(values)}`);
console.log(`a results: ${JSON.stringify(results)}`);
console.log(`a parameters: ${JSON.stringify(parameters)}`);
return 'one';
},
operations: [
{
key: 'b',
name: 'two',
async handler (options, results, parameters) {
console.log(`b options: ${JSON.stringify(options)}`);
console.log(`b results: ${JSON.stringify(results)}`);
console.log(`b parameters: ${JSON.stringify(parameters)}`);
return 'two'
}
}
]
}
]
});
await program.run(process.argv);
}()).catch(console.error);API
name: String(default: program)version: String(default: 0.0.0)operations: Array-operation: Object-key: String-name: String-description: String-options: Array<String,Object>-operations: Array<Object>-handler: AsyncFunction-options: ObjectAn object of name value pairs generated from the arguments following an operation. -results: ObjectAn object of name value pairs generated from the returned results from an operation. -parameters: ArrayThe remaining arguments from an operation.setup: AsyncFunction-options: Objecthas: AsyncFunction-data: StringName or keyfind: AsyncFunction-data: StringName or keyadd: AsyncFunction-operation: Objectexecute: AsyncFunction-operations: Array-operation: Objectrun: AsyncFunction-arguments: process.argvlog: FunctionWill print to console with color and style. -text: String-colors: Arrayinfo: FunctionWill print to console with color and style. (Default colorgreen) -text: String-colors: Arraywarn: FunctionWill print to console with color and style. (Default coloryellow) -text: String-colors: Arrayerror: FunctionWill print to console with color and style. (Default colorred) -text: String-colors: Array
Colors
- Style - reset - bold - dim - italic - underline - blink - inverse - hidden - strike
- Foreground - black - red - green - yellow - blue - magenta - cyan - white - gray - grey
- Background - bgBlack - bgRed - bgGreen - bgYellow - bgBlue - bgMagenta - bgCyan - bgWhite
Authors
License
Why You Should Choose MPL-2.0 This project is licensed under the MPL-2.0 License