yargs
========
Yargs be a node.js library fer hearties tryin' ter parse optstrings.
With yargs, ye be havin' a map that leads straight to yer treasure! Treasure of course, being a simple option hash.
[![Build Status][travis-image]][travis-url]
[![Dependency Status][gemnasium-image]][gemnasium-url]
[![Coverage Status][coveralls-image]][coveralls-url]
[![NPM version][npm-image]][npm-url]
[![Windows Tests][windows-image]][windows-url]
[![js-standard-style][standard-image]][standard-url]
[![standard-version][standard-version-image]][standard-version-url]
> Yargs is the official successor to optimist. Please feel free to submit issues and pull requests. If you'd like to contribute and don't know where to start, have a look at [the issue list](https://github.com/yargs/yargs/issues) :)
examples
========
With yargs, the options be just a hash!
-------------------------------------------------------------------
plunder.js:
````javascript
#!/usr/bin/env node
var argv = require('yargs').argv;
if (argv.ships > 3 && argv.distance < 53.5) {
console.log('Plunder more riffiwobbles!');
} else {
console.log('Retreat from the xupptumblers!');
}
````
***
$ ./plunder.js --ships=4 --distance=22
Plunder more riffiwobbles!
$ ./plunder.js --ships 12 --distance 98.7
Retreat from the xupptumblers!
![Joe was one optimistic pirate.](http://i.imgur.com/4WFGVJ9.png)
But don't walk the plank just yet! There be more! You can do short options:
-------------------------------------------------
short.js:
````javascript
#!/usr/bin/env node
var argv = require('yargs').argv;
console.log('(%d,%d)', argv.x, argv.y);
````
***
$ ./short.js -x 10 -y 21
(10,21)
And booleans, both long, short, and even grouped:
----------------------------------
bool.js:
````javascript
#!/usr/bin/env node
var argv = require('yargs').argv;
if (argv.s) {
process.stdout.write(argv.fr ? 'Le perroquet dit: ' : 'The parrot says: ');
}
console.log(
(argv.fr ? 'couac' : 'squawk') + (argv.p ? '!' : '')
);
````
***
$ ./bool.js -s
The parrot says: squawk
$ ./bool.js -sp
The parrot says: squawk!
$ ./bool.js -sp --fr
Le perroquet dit: couac!
And non-hyphenated options too! Just use `argv._`!
-------------------------------------------------
nonopt.js:
````javascript
#!/usr/bin/env node
var argv = require('yargs').argv;
console.log('(%d,%d)', argv.x, argv.y);
console.log(argv._);
````
***
$ ./nonopt.js -x 6.82 -y 3.35 rum
(6.82,3.35)
[ 'rum' ]
$ ./nonopt.js "me hearties" -x 0.54 yo -y 1.12 ho
(0.54,1.12)
[ 'me hearties', 'yo', 'ho' ]
Yargs even counts your booleans!
----------------------------------------------------------------------
count.js:
````javascript
#!/usr/bin/env node
var argv = require('yargs')
.count('verbose')
.alias('v', 'verbose')
.argv;
VERBOSE_LEVEL = argv.verbose;
function WARN() { VERBOSE_LEVEL >= 0 && console.log.apply(console, arguments); }
function INFO() { VERBOSE_LEVEL >= 1 && console.log.apply(console, arguments); }
function DEBUG() { VERBOSE_LEVEL >= 2 && console.log.apply(console, arguments); }
WARN("Showing only important stuff");
INFO("Showing semi-important stuff too");
DEBUG("Extra chatty mode");
````
***
$ node count.js
Showing only important stuff
$ node count.js -v
Showing only important stuff
Showing semi-important stuff too
$ node count.js -vv
Showing only important stuff
Showing semi-important stuff too
Extra chatty mode
$ node count.js -v --verbose
Showing only important stuff
Showing semi-important stuff too
Extra chatty mode
Tell users how to use yer options and make demands.
-------------------------------------------------
area.js:
````javascript
#!/usr/bin/env node
var argv = require('yargs')
.usage('Usage: $0 -w [num] -h [num]')
.demand(['w','h'])
.argv;
console.log("The area is:", argv.w * argv.h);
````
***
$ ./area.js -w 55 -h 11
The area is: 605
$ node ./area.js -w 4.91 -w 2.51
Usage: area.js -w [num] -h [num]
Options:
-w [required]
-h [required]
Missing required arguments: h
After yer demands have been met, demand more! Ask for non-hyphenated arguments!
-----------------------------------------
demand_count.js:
````javascript
#!/usr/bin/env node
var argv = require('yargs')
.demand(2)
.argv;
console.dir(argv);
````
***
$ ./demand_count.js a
Not enough non-option arguments: got 1, need at least 2
$ ./demand_count.js a b
{ _: [ 'a', 'b' ], '$0': 'demand_count.js' }
$ ./demand_count.js a b c
{ _: [ 'a', 'b', 'c' ], '$0': 'demand_count.js' }
EVEN MORE SHIVER ME TIMBERS!
------------------
default_singles.js:
````javascript
#!/usr/bin/env node
var argv = require('yargs')
.default('x', 10)
.default('y', 10)
.argv
;
console.log(argv.x + argv.y);
````
***
$ ./default_singles.js -x 5
15
default_hash.js:
````javascript
#!/usr/bin/env node
var argv = require('yargs')
.default({ x : 10, y : 10 })
.argv
;
console.log(argv.x + argv.y);
````
***
$ ./default_hash.js -y 7
17
And if you really want to get all descriptive about it...
---------------------------------------------------------
boolean_single.js:
````javascript
#!/usr/bin/env node
var argv = require('yargs')
.boolean('v')
.argv
;
console.dir(argv.v);
console.dir(argv._);
````
***
$ ./boolean_single.js -v "me hearties" yo ho
true
[ 'me hearties', 'yo', 'ho' ]
boolean_double.js:
````javascript
#!/usr/bin/env node
var argv = require('yargs')
.boolean(['x','y','z'])
.argv
;
console.dir([ argv.x, argv.y, argv.z ]);
console.dir(argv._);
````
***
$ ./boolean_double.js -x -z one two three
[ true, false, true ]
[ 'one', 'two', 'three' ]
Yargs is here to help you...
---------------------------
Ye can describe parameters fer help messages and set aliases. Yargs figures
out how ter format a handy help string automatically.
line_count.js:
````javascript
#!/usr/bin/env node
var argv = require('yargs')
.usage('Usage: $0 <command> [options]')
.command('count', 'Count the lines in a file')
.demand(1)
.example('$0 count -f foo.js', 'count the lines in the given file')
.demand('f')
.alias('f', 'file')
.nargs('f', 1)
.describe('f', 'Load a file')
.help('h')
.alias('h', 'help')
.epilog('copyright 2015')
.argv;
var fs = require('fs');
var s = fs.createReadStream(argv.file);
var lines = 0;
s.on('data', function (buf) {
lines += buf.toString().match(/\n/g).length;
});
s.on('end', function () {
console.log(lines);
});
````
***
$ node line_count.js count
Usage: line_count.js <command> [options]
Commands:
count Count the lines in a file
Options:
-f, --file Load a file [required]
-h, --help Show help [boolean]
Examples:
line_count.js count -f foo.js count the lines in the given file
copyright 2015
Missing required arguments: f
$ node line_count.js count --file line_count.js
26
$ node line_count.js count -f line_count.js
26
methods
=======
By itself,
````javascript
require('yargs').argv
````
will use the `process.argv` array to construct the `argv` object.
You can pass in the `process.argv` yourself:
````javascript
require('yargs')([ '-x', '1', '-y', '2' ]).argv
````
or use `.parse()` to do the same thing:
````javascript
require('yargs').parse([ '-x', '1', '-y', '2' ])
````
The rest of these methods below come in just before the terminating `.argv`.
<a name="alias"></a>.alias(key, alias)
------------------
Set key names as equivalent such that updates to a key will propagate to aliases
and vice-versa.
Optionally `.alias()` can take an object that maps keys to aliases.
Each key of this object should be the canonical version of the option, and each
value should be a string or an array of strings.
.argv
-----
Get the arguments
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
【作品名称】:基于python实现的区块链的供应链金融平台(含实验报告+源码) 【适用人群】:适用于希望学习不同技术领域的小白或进阶学习者。可作为毕设项目、课程设计、大作业、工程实训或初期项目立项。 【项目介绍】: 依赖环境 1. 链端与后端 Ubuntu 18.04 FISCO BCOS v2.1.0 Python 3.6.3+ FISCO BCOS Python SDK Flask 1.1 2. 前端 MacOS Xcode 二、文件说明 链端:Loan.sol 合约中实现完整供应链金融平台逻辑 后端:python-sdk/Loan_contract_invoke.py实现对Loan合约调用的封装;python-sdk/Loan_contract_flask_backend.py运行服务端,接受外部请求并返回JSON数据 前端:Loan_UI中是一个完整的iOSApp工程
资源推荐
资源详情
资源评论
收起资源包目录
基于python实现的区块链的供应链金融平台(含实验报告+源码) (1075个子文件)
client.log.20191208 113KB
stat.log.20191208 2KB
Loan.abi 4KB
SimpleInfo.abi 3KB
AddrTableWorker.abi 1KB
Permission.abi 630B
HelloWorld.abi 375B
AUTHORS 203B
AUTHORS 152B
Loan.bin 39KB
SimpleInfo.bin 7KB
HelloWorld.bin 2KB
Permission.bin 0B
range.bnf 619B
CHANGELOG 25B
cup.coffee 1B
mug.coffee 0B
node.crt 2KB
sdk.crt 2KB
ca.crt 1KB
.DS_Store 12KB
.DS_Store 8KB
.DS_Store 8KB
.editorconfig 264B
.eslintignore 13B
.eslintrc 1KB
.eslintrc 48B
.gitattributes 66B
.gitkeep 0B
AFURLSessionManager.h 30KB
AFURLRequestSerialization.h 22KB
AFHTTPSessionManager.h 20KB
AFURLResponseSerialization.h 12KB
UIButton+AFNetworking.h 10KB
AFImageDownloader.h 9KB
AFNetworkReachabilityManager.h 8KB
MASConstraint.h 8KB
AFAutoPurgingImageCache.h 6KB
MASUtilities.h 6KB
UIImageView+AFNetworking.h 6KB
AFSecurityPolicy.h 6KB
MASConstraintMaker.h 6KB
AFNetworkActivityIndicatorManager.h 5KB
View+MASAdditions.h 5KB
View+MASShorthandAdditions.h 5KB
UIWebView+AFNetworking.h 4KB
NSArray+MASAdditions.h 3KB
UIProgressView+AFNetworking.h 2KB
UIRefreshControl+AFNetworking.h 2KB
UIActivityIndicatorView+AFNetworking.h 2KB
MASConstraint+Private.h 2KB
UIKit+AFNetworking.h 2KB
AFNetworking.h 2KB
AFCompatibilityMacros.h 2KB
UIImage+AFNetworking.h 1KB
MASViewConstraint.h 1KB
MASViewAttribute.h 1KB
NSArray+MASShorthandAdditions.h 1016B
ViewController+MASAdditions.h 891B
Masonry.h 802B
CompanyResultViewController.h 572B
SearchCreditAssetViewController.h 567B
ReceiptResultCollectiionViewCell.h 516B
MASLayoutConstraint.h 505B
SearchReceiptViewController.h 503B
MASCompositeConstraint.h 494B
SearchCompanyViewController.h 493B
InitialViewController.h 473B
CreditAssetResultViewController.h 450B
ReceiptResultViewController.h 441B
AppDelegate.h 401B
NoResultViewController.h 373B
OperationCollectionViewCell.h 328B
NSLayoutConstraint+MASDebugAdditions.h 326B
ViewController.h 224B
UIActivityIndicatorView+AFNetworking.h 79B
UIActivityIndicatorView+AFNetworking.h 79B
AFNetworkActivityIndicatorManager.h 76B
AFNetworkActivityIndicatorManager.h 76B
UIRefreshControl+AFNetworking.h 72B
UIRefreshControl+AFNetworking.h 72B
UIProgressView+AFNetworking.h 70B
UIProgressView+AFNetworking.h 70B
UIImageView+AFNetworking.h 67B
UIImageView+AFNetworking.h 67B
AFAutoPurgingImageCache.h 66B
AFAutoPurgingImageCache.h 66B
UIWebView+AFNetworking.h 65B
AFNetworkReachabilityManager.h 65B
UIWebView+AFNetworking.h 65B
AFNetworkReachabilityManager.h 65B
UIButton+AFNetworking.h 64B
UIButton+AFNetworking.h 64B
NSLayoutConstraint+MASDebugAdditions.h 63B
UIImage+AFNetworking.h 63B
AFURLResponseSerialization.h 63B
NSLayoutConstraint+MASDebugAdditions.h 63B
UIImage+AFNetworking.h 63B
AFURLResponseSerialization.h 63B
AFURLRequestSerialization.h 62B
共 1075 条
- 1
- 2
- 3
- 4
- 5
- 6
- 11
资源评论
MarcoPage
- 粉丝: 3443
- 资源: 4283
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于Bagging集成学习方法的情绪分类预测模型研究(数据集+代码).rar
- nacos-server-2.3.0-BETA.zip
- 双11活动数据分析-商品销售数据、促销活动的信息、用户行为数据
- 基于记忆与模型协同过滤的电影推荐系统研究与实践(数据集+代码).rar
- 基于LDA主题分析的《老友记》情景喜剧数据集的建模分析(数据集+代码).rar
- html css js网页制作实例-展示一个基本的交互效果
- DevExpress控件通用导出Excel,支持多个控件同时导出
- 基于情感分析+聚类分析+LDA主题分析对服装产品类的消费者评论分析(数据集+代码).rar
- 编译原理-研究如何将高级语言编写的程序转换成计算机能够执行的低级指令或者其他形式的表达
- php中ImageMagick安装教程;ImageMagick安装包;ImageMagick安装注意事项;pdf转img
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功