@noresources/command

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

A lightweight command line interface definition package focusing on reusability, extensibility and a clean API

原始使用文档
文档目录6 节
  1. Installation
  2. Features
  3. Examples
  4. Component descriptors
  5. Builder API
  6. Exporter to commander.js

@noresources/command

A lightweight command line interface definition package focusing on reusability, extensibility and a clean API.

Installation

npm install --save @noresources/command

Features

  • Plain object based command component descriptors
    • Program
    • Command, subcommands
    • Option
    • Positional
    • Parameter (option and positional argument value type)
  • Chain-based program builder API
  • Exporter to well-known command packages

Examples

Component descriptors

Commands, options and positional arguments can be declared using a simple plain javascript object.

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

Then, a factory function will creates the correct class instance.

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

Builder API

The ProgramBuilder class provides a fluent interface to define the whole program interface using method chaining.

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'),
    })

Exporter to commander.js

For now, this package does not provide a command line parser by itself. It relies on well established parser Commander.jsa to for parsing.

Converting a @noresources/command program to a Commander.js command is made with a simple function call.

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

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

Note that the commander package is not included in @noresources/command package dependencies. You have to install it manually to usie this feature.

版本与发布记录

@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 和提交记录判断。