You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 11, 2024. It is now read-only.
Interface to decouple executables from library code.
This module complements the command module to encourage decoupling executable code from the program configuration which makes it easier to test and generate code coverage for command line programs.
Install
npm install cli-interface
Test
npm test
Usage
Create a subclass of the Interface class to create the library file (main.js):
Note all methods are invoked in the scope of the CommandProgram instance. Then create an executable file assuming it is located in a bin directory and main.js is in the package root:
Just require your main file (main.js) and pass an arguments array to parse() to assert on your program's behaviour.
API
([pkg], [name], [description])
Create an Interface instance.
pkg: A package object or string path to package.json.
name: The program name.
description: The program description.
Returns an Interface instance.
Interface
The Interface class is an abstraction that encapsulates a CommandProgram
instance assigned to the program property.
Interface([pkg], [name], [description])
Create an Interface instance.
pkg: A package object or string path to package.json.
name: The program name.
description: The program description.
configure()
Invoked by the constructor to configure the program, scope is the CommandProgram, you should call this.configure({...}) within this method to configure the program.
use()
Invoked by the constructor to configure middleware for the program, scope is the CommandProgram, you should call this.use() within this method to configure the program middleware.
command()
Invoked by the constructor to configure command options for the program, scope is the CommandProgram, you should call this.command() within this method to configure the program command options.
option()
Invoked by the constructor to configure argument options for the program, scope is the CommandProgram, you should call this.option() within this method to configure the program argument options.
parse([args])
Proxies to the parse() method of the program.
args: An array of arguments to pass to the program, default is process.argv.slice(2).
program
A reference to the encapsulated CommandProgram instance.
License
Everything is MIT. Read the license if you feel inclined.
About
Interface to decouple executables from library code