@absolunet/cli 中文文档教程
@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])
从 js 文件名构建任务列表
options.pkgPath
类型:string
package.json
文件夹的路径
options.pkg
类型:object
package.json
-like object
API - Tasks
initTasksList(tasksPath)
从 js 文件名构建任务列表
tasksPath
必需
类型:字符串
任务文件夹的路径
tasksRouter(meowCli)
需要 CLI 指定的任务文件
meowCli
必需
类型:对象
meow object
tasks
类型:Array
任务列表
API - Usage
placeholder(name)
看占位符
返回已查找占位符的 string
name
必需
类型:字符串
Text to theme
optional(name)
看起来可选
返回看起来可选的 string
name
Required
类型:字符串
文本到主题
optionalPlaceholder(name)
看可选的占位符
返回看起来可选的占位符的 string
name
Required
类型:字符串
Text to theme
setUsageTasks(commands)
设置任务使用和自动完成数据
commands
必需
类型:对象
检查结构示例
setFullUsage(fullUsage [, options])
设置完整的使用结构
fullUsage
必需
类型:对象
检查结构
options.showBin
类型的示例:boolean
显示版本和 bin 位置
默认值:true
getTaskUsage(task)
获取任务使用情况
返回任务使用的 string
task
必需
类型:字符串
检查结构示例
showTaskUsage(meowCli)
显示任务使用情况并退出
meowCli
必需
类型:对象
meow object
fullUsage
类型:string
格式化为用户手册的描述和任务
API - Helpers
refuseArguments(meowCli)
如果 CLI 调用有参数,则显示任务使用情况并退出
meowCli
必需
类型:对象
meow 对象
ow
类型:对象
本地 ow
的实例
refuseFlags(meowCli)
如果 CLI 调用有标志,则显示任务使用情况并退出
meowCli
必需
类型:对象
meow object
refuseFlagsAndArguments(meowCli)
如果 CLI 调用有参数或标志,则显示任务使用情况并退出
meowCli
必需
类型:对象
meow object
validateFlags(meowCli, flag)
如果 CLI 调用具有未列入白名单且未验证的标志,则显示任务使用情况并退出
返回标志值的对象
meowCli
必需
类型:对象
喵对象
flagValidations
必需
类型:标志验证器的对象
白名单标志及其 ow
predicate(使用 cli.ow
以确保使用相同的版本)
isRoot()
检查 CLI 是否由 root 用户运行
返回 boolean
binName
类型:string
二进制名称
rawArguments
类型:string
来自终端的空格分隔参数
License
麻省理工学院 © Absolunet
@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 filenames
options.pkgPath
Type: string
Path to package.json
folder
options.pkg
Type: object
package.json
-like object
API - Tasks
initTasksList(tasksPath)
Build tasks list from js filenames
tasksPath
Required
Type: string
Path to tasks folder
tasksRouter(meowCli)
Require task file specified by CLI
meowCli
Required
Type: object
meow object
tasks
Type: Array
List of tasks
API - Usage
placeholder(name)
Look placeholder
Return string
of looked placeholder
name
Required
Type: string
Text to theme
optional(name)
Look optional
Return string
of looked optional
name
Required
Type: string
Text to theme
optionalPlaceholder(name)
Look optional placeholder
Return string
of looked optional placeholder
name
Required
Type: string
Text to theme
setUsageTasks(commands)
Set tasks usage and autocomplete data
commands
Required
Type: object
Check example for structure
setFullUsage(fullUsage [, options])
Set full usage structure
fullUsage
Required
Type: object
Check example for structure
options.showBin
Type: boolean
Show version and bin location
Default: true
getTaskUsage(task)
Get task usage
Return string
of task usage
task
Required
Type: string
Check example for structure
showTaskUsage(meowCli)
Display task usage and quit
meowCli
Required
Type: 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 arguments
meowCli
Required
Type: object
meow object
ow
Type: Object
Instance of local ow
refuseFlags(meowCli)
Show task usage and quit if CLI call has flags
meowCli
Required
Type: object
meow object
refuseFlagsAndArguments(meowCli)
Show task usage and quit if CLI call has arguments or flags
meowCli
Required
Type: object
meow object
validateFlags(meowCli, flag)
Show task usage and quit if CLI call has flags that are not whitelisted and do not validate
Return object
of flags values
meowCli
Required
Type: object
meow object
flagValidations
Required
Type: object
of flag validators
Whitelisted flags and their ow
predicate (use cli.ow
to ensure to use the same version)
isRoot()
Check if CLI is run by root user
Return boolean
binName
Type: string
Binary name
rawArguments
Type: string
Space separated arguments from terminal
License
MIT © Absolunet
你可能也喜欢
- @2alheure/vue-safe-mail 中文文档教程
- @36node/fetch 中文文档教程
- @3imed-jaberi/deepfreeze 中文文档教程
- @4geit/rct-unlink-project 中文文档教程
- @59naga/gbf-data 中文文档教程
- @_pearofducks/require-extension-hooks-vue 中文文档教程
- @a.abunada/expo-location 中文文档教程
- @abext/search 中文文档教程
- @abide-community/parcel-plugin-clean-out-dir 中文文档教程
- @ablegroup/checkgroup 中文文档教程