@noresources/command

中文文档
0.2.0发布于 2026/11/02ISCES Module

一个轻量级的命令行接口定义包,专注于可重用性、可扩展性和干净的API

中文使用文档
文档目录6 节
  1. 安装
  2. 功能
  3. 示例
  4. 组件描述符
  5. 构建器API
  6. 导出到commander.js

@noresources /命令

一个轻量级的命令行接口定义包,专注于可重用性、可扩展性和干净的API。

安装

npm install --save @noresources/command

功能

  • 基于普通对象的命令组件描述符
    • 程序
    • 命令,子命令
    • 选项
    • 位置
    • 参数(选项和位置参数值类型)
  • 基于链的程序构建器API
  • 导出到众所周知的命令包

示例

组件描述符

命令、选项和位置参数可以使用一个简单的javascript对象来声明。

export const Verbosity = {
    'type': 'counter',
    'documentation': 'Verbosity level',
    'initial': 0,
    'names': ['verbosity', 'v']
};

然后,工厂函数将创建正确的类实例。

import { createOption } from "@noresources/command"
const option = createOption(Verbosity);

构建器API

这个 ProgramBuilder 类提供了一个流畅的接口,以使用方法链定义整个程序接口。

import { ProgramBuilder } from "@noresources/command"

const builder = new ProgramBuilder;
builder.name('chatbot')
    .version('1.2.3')
    .option(Verbosity) // out option descriptor presented above.
    .positional({
        documentation: 'Some text to insert in conversation'
    }).handler(function (input) {
            if (input.options.verbosity > 2) console.log('Bark bark')
            if (input.arguments.length)
                console.log (input.arguments[0])
            console.log ('This program is not really meaningful'),
    })

导出到commander.js

目前,这个包本身不提供命令行解析器。它依赖于完善的解析器 Commander.js用于解析的to。

转换 @noresources/command 程序到a Commander.js 命令是通过一个简单的函数调用生成的。

import {	createCommand } from '@noresources/command/commander'

const command = createCommand(builder.program); // assuming builder is the ProgramBuilder instance defined above.
command.parse ();

请注意 commander 包不包括在 @noresources/command 包依赖关系。您必须手动安装它才能使用此功能。

版本与发布记录

@noresources/command 共发布 5 个版本,首次发布于 2026/10/26;过去 12 个月发布了 5 个版本。

版本发布日期距今
0.2.0latest2026/11/021 天前
0.1.22026/10/304 天前
0.1.12026/10/286 天前
0.1.02026/10/268 天前
0.0.0-stage2026/10/268 天前

关于 @noresources/command 的常见问题

@noresources/command 是什么?

一个轻量级的命令行接口定义包,专注于可重用性、可扩展性和干净的API

如何安装 @noresources/command?

在项目目录运行 npm install @noresources/command,或使用 pnpm add / yarn add / bun add。

@noresources/command 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/noresources__command 是否存在。

@noresources/command 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@noresources/command 可以商用吗?

@noresources/command 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@noresources/command 还在维护吗?

最新版本 0.2.0 发布于 2026/11/02(1 天前);至今共发布 5 个版本,其中过去 12 个月发布了 5 个;首次发布于 2026/10/26。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。