expose-cli
Simple Way To Run Your Local Function From CLI
node index.js localFunction arg1 arg2 arg3
Installation
# NPM npm i expose-cli # Yarn yarn add expose-cli
Example Usage
index.js
const exposeCli = ; { console;} { console;} { return { console; ; };} const printClosure = { console;}; { console;} { console;} { console;} { console;} { return 'Returned from `returnSync`';} { return 'Returned from `returnAsync`';} { return ;} ;
Run local function
Execute
node index.js printSyncWithArg world
Output
Printed from printSyncWithArg: world
help
Print all listed handler with command Execute command
node index.js printSyncWithArg help
Output
IMPORTANT!
The help
command will display an <unreachable>
message if you use:
- Closure function. Ex:
() => {}
- Rest arguments. Ex:
function(...args)
- Function stored in a variable. Ex:
const handler= function() {}
- A method in a Class
- Anonymous function
Calling Format
exposeCli(handlers, [config])
handlers
Format (Object):
command
: handler
command
:string
handler
:function
orobject
- name:
string
- args:
array
- description:
string
- handler:
function
- name:
config
// Print returned value from function called printReturn: false // default // Trigger process.exit() when finished exitOnSuccess: true // default // Trigger process.exit(1) when error exitOnError: true // default // cutom log handler customConsoleLog: consolelog // default customConsoleError: consoleerror // default // custom command `help` name customHelpName: 'help' // default // custom additional command `help` options customHelp: handler: defaultHelpHandler name: 'help' args: '' description: 'Show all the functions listed.' // default
Support
- Can be used using webpack
- Supports calling
async
function or function that returnPromise
or closure - Supports function that
throw
an error
Change Log
v0.0.2
- Fixed bugs
- Added default handler for
help
- Support
object
format forhandlers
arguments