@absolunet/cli
CLI utilities
Built around meow
Install
$ npm install @absolunet/cli
Usage
const cli = require('@absolunet/cli');
cli.initTasksList('./tasks');
cli.setUsageTasks({
// Base
'start': ['start', 'Start project'],
'stop': ['stop', 'Stop project'],
'log': [`log ${cli.optionalPlaceholder('<sub>')}`, 'Show log for sub', ['sub1', 'sub2']],
// Options
'--help': ['-h, --help', 'Show help'],
'--version': ['-v, --version', 'Show version']
});
cli.setFullUsage({
'Base': ['start', 'stop', 'log'],
'Options': ['--help', '--version']
});
console.log(cli.fullUsage);
Test project description
Usage: testprj <command>
Base
start Start project
stop Stop project
log [<sub>] Show log for sub [sub1|sub2]
Options
-h, --help Show help
-v, --version Show version
testprj@1.2.3 /usr/local/bin/testprj
init([options])
Build tasks list from js filenamesoptions.pkgPath
Type:string
Path to
package.json
folderoptions.pkg
Type:object
package.json
-like objectAPI - Tasks
initTasksList(tasksPath)
Build tasks list from js filenamestasksPath
RequiredType:
string
Path to tasks folder
tasksRouter(meowCli)
Require task file specified by CLImeowCli
RequiredType:
object
meow object
tasks
Type: Array
List of tasks
API - Usage
placeholder(name)
Look placeholderReturn
string
of looked placeholdername
RequiredType:
string
Text to theme
optional(name)
Look optionalReturn
string
of looked optionalname
RequiredType:
string
Text to theme
optionalPlaceholder(name)
Look optional placeholderReturn
string
of looked optional placeholdername
RequiredType:
string
Text to theme
setUsageTasks(commands)
Set tasks usage and autocomplete datacommands
RequiredType:
object
Check example for structure
setFullUsage(fullUsage [, options])
Set full usage structurefullUsage
RequiredType:
object
Check example for structure
options.showBin
Type:boolean
Show version and bin location
Default: true
getTaskUsage(task)
Get task usageReturn
string
of task usagetask
RequiredType:
string
Check example for structure
showTaskUsage(meowCli)
Display task usage and quitmeowCli
RequiredType:
object
meow object
fullUsage
Type: string
Description and tasks formatted as a user manual
API - Helpers
refuseArguments(meowCli)
Show task usage and quit if CLI call has argumentsmeowCli
RequiredType:
object
meow object
ow
Type: Object
Instance of local
ow
refuseFlags(meowCli)
Show task usage and quit if CLI call has flagsmeowCli
RequiredType:
object
meow object
refuseFlagsAndArguments(meowCli)
Show task usage and quit if CLI call has arguments or flagsmeowCli
RequiredType:
object
meow object
validateFlags(meowCli, flag)
Show task usage and quit if CLI call has flags that are not whitelisted and do not validateReturn
object
of flags valuesmeowCli
RequiredType:
object
meow object
flagValidations
RequiredType:
object
of flag validatorsWhitelisted flags and their
ow
predicate (use cli.ow
to ensure to use the same version)isRoot()
Check if CLI is run by root userReturn
boolean
binName
Type: string
Binary name
rawArguments
Type: string
Space separated arguments from terminal