<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Commander.js——模具行业从业者必备知识手册]]></title><description><![CDATA[<p dir="auto">&lt;h2&gt;Commander.js&lt;/h2&gt;</p>
<p dir="auto">&lt;p&gt;&lt;a href="<a href="https://api.travis-ci.org/tj/commander.js.svg?branch=master" rel="nofollow ugc">https://api.travis-ci.org/tj/commander.js.svg?branch=master</a>"&gt;&lt;img src="<a href="http://travis-ci.org/tj/commander.js" rel="nofollow ugc">http://travis-ci.org/tj/commander.js</a>" alt="Build Status&lt;/a&gt;"&gt;&lt;/p&gt;<br />
&lt;p&gt;&lt;a href="upload://ycssy0jEccPEmH8C3gZRrKMZAom.svg"&gt;&lt;img src="<a href="https://www.npmjs.org/package/commander" rel="nofollow ugc">https://www.npmjs.org/package/commander</a>" alt="NPM Version&lt;/a&gt;"&gt;&lt;/p&gt;<br />
&lt;p&gt;&lt;a href="upload://mF8yDNPeD4ziKbXSq5OEepnK4wo.svg"&gt;&lt;img src="<a href="https://npmcharts.com/compare/commander?minimal=true" rel="nofollow ugc">https://npmcharts.com/compare/commander?minimal=true</a>" alt="NPM Downloads&lt;/a&gt;"&gt;&lt;/p&gt;<br />
&lt;p&gt;&lt;a href="<a href="https://packagephobia.now.sh/badge?p=commander" rel="nofollow ugc">https://packagephobia.now.sh/badge?p=commander</a>"&gt;&lt;img src="<a href="https://packagephobia.now.sh/result?p=commander" rel="nofollow ugc">https://packagephobia.now.sh/result?p=commander</a>" alt="Install Size&lt;/a&gt;"&gt;&lt;/p&gt;<br />
&lt;p&gt;&lt;a href="upload://iAIY16dpQcK4uPfXQJKuIKHvFBe.svg"&gt;&lt;img src="<a href="https://gitter.im/tj/commander.js?utm_source=badge&amp;utm_medium=badge&amp;utm_campaign=pr-badge&amp;utm_content=badge" rel="nofollow ugc">https://gitter.im/tj/commander.js?utm_source=badge&amp;utm_medium=badge&amp;utm_campaign=pr-badge&amp;utm_content=badge</a>" alt="Join the chat at <a href="https://gitter.im/tj/commander.js" rel="nofollow ugc">https://gitter.im/tj/commander.js</a>&lt;/a&gt;"&gt;&lt;/p&gt;</p>
<p dir="auto">&lt;p&gt;  The complete solution for &lt;a href="<a href="http://nodejs.org" rel="nofollow ugc">http://nodejs.org</a>"&gt;node.js&lt;/a&gt; command-line interfaces, inspired by Ruby's &lt;a href="<a href="https://github.com/commander-rb/commander" rel="nofollow ugc">https://github.com/commander-rb/commander</a>"&gt;commander&lt;/a&gt;.  &lt;/p&gt;<br />
&lt;p&gt;  &lt;a href="<a href="http://tj.github.com/commander.js/" rel="nofollow ugc">http://tj.github.com/commander.js/</a>"&gt;API documentation&lt;/a&gt;&lt;/p&gt;</p>
<p dir="auto">&lt;h3&gt;Installation&lt;/h3&gt;</p>
<p dir="auto">&lt;p&gt;    $ npm install commander&lt;/p&gt;</p>
<p dir="auto">&lt;h3&gt;Option parsing&lt;/h3&gt;</p>
<p dir="auto">&lt;p&gt;Options with commander are defined with the &lt;code&gt;.option()&lt;/code&gt; method, also serving as documentation for the options. The example below parses args and options from &lt;code&gt;process.argv&lt;/code&gt;, leaving remaining args as the &lt;code&gt;program.args&lt;/code&gt; array which were not consumed by options.&lt;/p&gt;</p>
<p dir="auto">&lt;pre&gt;&lt;code&gt;<br />
#!/usr/bin/env node</p>
<p dir="auto">/**</p>
<ul>
<li>Module dependencies.<br />
*/</li>
</ul>
<p dir="auto">var program = require('commander');</p>
<p dir="auto">program<br />
.version('0.1.0')<br />
.option('-p, --peppers', 'Add peppers')<br />
.option('-P, --pineapple', 'Add pineapple')<br />
.option('-b, --bbq-sauce', 'Add bbq sauce')<br />
.option('-c, --cheese [type]', 'Add the specified type of cheese [marble]', 'marble')<br />
.parse(process.argv);</p>
<p dir="auto">console.log('you ordered a pizza with:');<br />
if (program.peppers) console.log('  - peppers');<br />
if (program.pineapple) console.log('  - pineapple');<br />
if (program.bbqSauce) console.log('  - bbq');<br />
console.log('  - %s cheese', program.cheese);<br />
&lt;/code&gt;&lt;/pre&gt;</p>
<p dir="auto">&lt;p&gt;Short flags may be passed as a single arg, for example &lt;code&gt;-abc&lt;/code&gt; is equivalent to &lt;code&gt;-a -b -c&lt;/code&gt;. Multi-word options such as "--template-engine" are camel-cased, becoming &lt;code&gt;program.templateEngine&lt;/code&gt; etc.&lt;/p&gt;</p>
<p dir="auto">&lt;p&gt;Note that multi-word options starting with &lt;code&gt;--no&lt;/code&gt; prefix negate the boolean value of the following word. For example, &lt;code&gt;--no-sauce&lt;/code&gt; sets the value of &lt;code&gt;program.sauce&lt;/code&gt; to false.&lt;/p&gt;</p>
<p dir="auto">&lt;pre&gt;&lt;code&gt;<br />
#!/usr/bin/env node</p>
<p dir="auto">/**</p>
<ul>
<li>Module dependencies.<br />
*/</li>
</ul>
<p dir="auto">var program = require('commander');</p>
<p dir="auto">program<br />
.option('--no-sauce', 'Remove sauce')<br />
.parse(process.argv);</p>
<p dir="auto">console.log('you ordered a pizza');<br />
if (program.sauce) console.log('  with sauce');<br />
else console.log(' without sauce');<br />
&lt;/code&gt;&lt;/pre&gt;</p>
<p dir="auto">&lt;p&gt;To get string arguments from options you will need to use angle brackets &lt;&gt; for required inputs or square brackets [] for optional inputs. &lt;/p&gt;</p>
<p dir="auto">&lt;p&gt;e.g. &lt;code&gt;<code>&lt;/code&gt;.option('-m --myarg [myVar]', 'my super cool description')&lt;code&gt;</code>&lt;/code&gt;&lt;/p&gt;</p>
<p dir="auto">&lt;p&gt;Then to access the input if it was passed in.&lt;/p&gt;</p>
<p dir="auto">&lt;p&gt;e.g. &lt;code&gt;<code>&lt;/code&gt;var myInput = program.myarg&lt;code&gt;</code>&lt;/code&gt;&lt;/p&gt;</p>
<p dir="auto">&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt;: If you pass a argument without using brackets the example above will return true and not the value passed in.&lt;/p&gt;</p>
<p dir="auto">&lt;h3&gt;Version option&lt;/h3&gt;</p>
<p dir="auto">&lt;p&gt;Calling the &lt;code&gt;version&lt;/code&gt; implicitly adds the &lt;code&gt;-V&lt;/code&gt; and &lt;code&gt;--version&lt;/code&gt; options to the command.&lt;/p&gt;<br />
&lt;p&gt;When either of these options is present, the command prints the version number and exits.&lt;/p&gt;</p>
<p dir="auto">&lt;p&gt;    $ ./examples/pizza -V&lt;/p&gt;<br />
&lt;p&gt;    0.0.1&lt;/p&gt;</p>
<p dir="auto">&lt;p&gt;If you want your program to respond to the &lt;code&gt;-v&lt;/code&gt; option instead of the &lt;code&gt;-V&lt;/code&gt; option, simply pass custom flags to the &lt;code&gt;version&lt;/code&gt; method using the same syntax as the &lt;code&gt;option&lt;/code&gt; method.&lt;/p&gt;</p>
<p dir="auto">&lt;pre&gt;&lt;code&gt;<br />
program<br />
.version('0.0.1', '-v, --version')<br />
&lt;/code&gt;&lt;/pre&gt;</p>
<p dir="auto">&lt;p&gt;The version flags can be named anything, but the long option is required.&lt;/p&gt;</p>
<p dir="auto">&lt;h3&gt;Command-specific options&lt;/h3&gt;</p>
<p dir="auto">&lt;p&gt;You can a&lt;/p&gt;</p>
<p dir="auto">&lt;hr&gt;<br />
&lt;p&gt;各位师傅觉得这个方案怎么样？有更好的做法吗？&lt;/p&gt;</p>
]]></description><link>https://forum.mj7.cn/topic/7190/commander-js-模具行业从业者必备知识手册</link><generator>RSS for Node</generator><lastBuildDate>Fri, 02 Oct 2026 10:19:40 GMT</lastBuildDate><atom:link href="https://forum.mj7.cn/topic/7190.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 19 Apr 2026 21:50:10 GMT</pubDate><ttl>60</ttl></channel></rss>