Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ldarren/pico-args
pico command line arguments parser
https://github.com/ldarren/pico-args
argument argument-parser
Last synced: 7 days ago
JSON representation
pico command line arguments parser
- Host: GitHub
- URL: https://github.com/ldarren/pico-args
- Owner: ldarren
- License: mit
- Created: 2016-07-26T15:01:08.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-04-16T02:23:12.000Z (almost 2 years ago)
- Last Synced: 2024-11-30T19:13:14.902Z (2 months ago)
- Topics: argument, argument-parser
- Language: JavaScript
- Size: 13.7 KB
- Stars: 0
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pico Arguments Library
Yet another barebone command line arguments library## Usage
### defined default arguments
```javascript
var defaults={
name: ['{DEFAULT_NAME}','{DESCRIPTION}'],
n:'@name'
}
```
this is the default for
```
CMD --name xyz
```
or
```
CMD -n xyz
```
### data type
supported 4 datatypes: string, boolean, number and object/array
to set string type
```javascript
var defaults={
str: ['default','default str is "default"'],
s:'@str'
}
```
to set boolean type
```javascript
var defaults={
bool: [false,'default bool is false'],
b:'@bool'
}
```
set it to true
```
CMD -b # or CMD --bool
```
set it to false
```
CMD -B # or CMD --BOOL
```
to set number type
```javascript
var defaults={
float: [0,'default float is 0'],
f:'@float'
}
```
to set object type
```javascript
var defaults={
obj: [{foo:"bar"},'default obj is {foo:"bar"}'],
o:'@obj'
}
```
or
```javascript
var defaults={
obj: [['foo','bar'],'default obj is ["foo","bar"]'],
o:'@obj'
}
```
```
CMD -o '{"hello":"world"}' #or CMD --obj '{"hello":"world"}'
```
### parse arguments
```javascript
var
args=require('pico-args'),
options=args.parse(defaults)console.log(options.name)
console.log(options.n)
```
### print arguments
this function requires pico-common module
```javascript
args.print('{TITLE}',options)
```
### print usage
this function requires pico-common module
```javascript
args.usage(defaults)
```
### argument combo
single character arguments can be string in one word
```javascript
var defaults={
a:[true,'flag a'],
b:[false,'flag b'],
c:[true,'flag c'],
d:['/opt/','path']
}
```
```
CMD -Abcd '~/src'
```