npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jz-custom-cli

v1.0.8

Published

An application for jiuZhe

Downloads

590

Readme

option选项类型如下:

获取选项: const options = program.opts();

解析器:

function handleFirst(value) {

return value

}

不带参数

option('-f, --first', '这是一个布尔类型的参数'):固定值是false

option('-f, --first', '这是一个布尔类型的参数', handleFirst):固定值是false;解析器:handleFirst

执行命令:node index.js -f :输出:错误

单个参数

option('-a, --aCount ', '这是一个参数')

option('-a, --aCount ', '这是一个参数', 100) :默认值是100

option('-a, --aCount ', '这是一个参数', 100, handleACount):默认值是100;解析器:handleCount

执行命令:node index.js -a 200 :输出:201

多个参数。备注:没有解析器

option('-b, --bCount <number...>', '这是一个参数')

执行命令:node index.js -b 200 300 400 :输出:[200, 300, 400]

定义一个以no-开头的 boolean 型长选项。

.option('--no-pay', '这是一个布尔类型的参数'); node index.mjs:输出:{ payCount: true } node index.mjs --no-payCount :输出:{ payCount: false }

.option('--payCount ', '这是一个布尔类型的参数', handleFirst, 222);node index.mjs --payCount :输出:{ payCount: 222 }

可选参数类型(不能设置默认值),在命令行中使用该选项时,带参数时,使用的参数,否则是布尔值true;

option('-c, --cCount [type]', '这是可选参数类型');node index.mjs -c :输出:{ cCount: true }

option('-c, --cCount [type]', '这是可选参数类型');node index.mjs -c 111:输出:{ cCount: 111 }

必填参数(不能设置默认值)

requiredOption('-d, --dCount ', '这是必填参数');node index.mjs -d 111:输出:{ dCount: 111 }

隐藏帮助信息

addOption(new Option('-s, --secret').hideHelp());node index.mjs -h;看不到此选项

新增选项 new Option

addOption(new Option('-t, --timeout ', 'timeout in seconds').default(60, 'one minute')):默认值

addOption(new Option('-d, --drink ', 'drink size').choices(['small', 'medium', 'large'])):固定选项值

addOption(new Option('-po, --port ', 'port number').env('PORT')):使用 .env 方法:指定了一个环境变量 PORT,如果用户没有通过命令行传递端口号,Commander.js 会尝试从环境变量中获取值。

addOption(new Option('--free-drink', 'small drink included free ').implies({ a: '安徽省', b: '合肥市', c: '包河区' }));:使用 .implies 方法:执行该命令,意味输出 a: '安徽省', b: '合肥市', c: '包河区'。

command('add'):创建一个命令

argument('<params...>', '添加多个参数'):添加一个参数

addArgument(new Argument('', 'drink cup size').choices(['small', 'medium', 'large'])): 添加指定参数

option 方法一样,默认值、默认值、固定选项值