Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
zakkudo committed Feb 6, 2019
0 parents commit 9ac7a2f
Show file tree
Hide file tree
Showing 30 changed files with 7,415 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true

# Matches multiple files with brace expansion notation
# Set default charset
[*.js]
charset = utf-8
indent_style = space
indent_size = 2
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
build
yarn-error.log
documentation
coverage
*.swp
.DS_Store
4 changes: 4 additions & 0 deletions .snyk
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
version: v1.12.0
ignore: {}
patch: {}
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: node_js
cache: yarn
node_js:
- "8"
- "10"
- "11"
install:
- yarn add --dev codecov snyk coveralls
script:
- yarn cover
- cat coverage/lcov.info | ./node_modules/.bin/coveralls
- ./node_modules/.bin/codecov
- ./node_modules/.bin/snyk test
29 changes: 29 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BSD 3-Clause License

Copyright (c) 2019, Zachary Dovel
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11 changes: 11 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Copyright 2018 Zachary Dovel

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
180 changes: 180 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
# @zakkudo/argument-parser

Make parsing node command line arguments enjoyable.

[![Build Status](https://travis-ci.org/zakkudo/argument-parser.svg?branch=master)](https://travis-ci.org/zakkudo/argument-parser)
[![Coverage Status](https://coveralls.io/repos/github/zakkudo/argument-parser/badge.svg?branch=master)](https://coveralls.io/github/zakkudo/argument-parser?branch=master)
[![Known Vulnerabilities](https://snyk.io/test/github/zakkudo/argument-parser/badge.svg)](https://snyk.io/test/github/zakkudo/argument-parser)
[![Node](https://img.shields.io/node/v/@zakkudo/argument-parser.svg)](https://nodejs.org/)
[![License](https://img.shields.io/npm/l/@zakkudo/argument-parser.svg)](https://opensource.org/licenses/BSD-3-Clause)

## Why use this?

- Straight forward configuration
- Reusability

## What does it do?

- Parses arguments using multiple configuration types

## Install

```console
# Install using npm
npm install @zakkudo/argument-parser
```

``` console
# Install using yarn
yarn add @zakkudo/argument-parser
```

## Examples

### Basic example
``` javascript
const parse = new ArgumentParser({
name: 'download-program',
version: 'v1.3.4',
description: 'A program for downloading files very fastly.',
leftover: 'files',
schema: [{
long: 'fast',
short: 'f',
type: 'boolean',
description: 'Makes the download go very fast.',
}, {
long: 'token',
short: 't',
type: 'string',
description: 'Token used for authentication.',
}, {
long: 'muliplier',
short: 'm',
type: 'float',
description: 'How many times faster the download should be.',
}, {
long: 'servers',
type: 'list',
typeName: 's1,s2,s3',
description: 'Servers to use for the fast downloading, separated by a comma.',
}]
});

const parsed = parse(['--fast', '--token', '1234', 'src/**/*.js', ]
// Returns an object with the below:
// {
// "fast": true,
// "leftover": [
// "src/**/*.js",
// ],
// "token": "1234",
// }

parse(['--version']
// Exits, printing: "download-program version v1.3.4"

parse(['--help'])
// Exits, printing:
// usage: download-program [--help] [--version] [--fast] [--token=uuid] [--muliplier=float] [--servers=s1,s2,s3] ...files
// A program for downloading files very fastly.
//
// -h/--help Show this help information.
// -V/--version Show the program version.
// -f/--fast Makes the download go very fast.
// -t/--token=uuid Token used for authentication.
// -m/--muliplier=float How many times faster the download should be.
// --servers=s1,s2,s3 Servers to use for the fast downloading, separated by a comma.
```
## API
<a name="module_@zakkudo/argument-parser"></a>
<a name="module_@zakkudo/argument-parser..ArgumentParser"></a>
### @zakkudo/argument-parser~ArgumentParser ⏏
**Kind**: Exported class
* [~ArgumentParser](#module_@zakkudo/argument-parser..ArgumentParser)
* [new ArgumentParser(options)](#new_module_@zakkudo/argument-parser..ArgumentParser_new)
* [~ParseFunction](#module_@zakkudo/argument-parser..ArgumentParser..ParseFunction) ⇒ <code>Object</code>
* [~Schema](#module_@zakkudo/argument-parser..ArgumentParser..Schema) : <code>Object</code>
* [~Options](#module_@zakkudo/argument-parser..ArgumentParser..Options) : <code>Object</code>
<a name="new_module_@zakkudo/argument-parser..ArgumentParser_new"></a>
#### new ArgumentParser(options)
| Param | Type | Description |
| --- | --- | --- |
| options | [<code>Options</code>](#module_@zakkudo/argument-parser..ArgumentParser..Options) | The configuration options for how parsing is done. returns {module:@zakkudo/argument-parser~ArgumentParser~ParseFunction} A function used to parse arguments given the configuration during construction. |
<a name="module_@zakkudo/argument-parser..ArgumentParser..ParseFunction"></a>
#### ArgumentParser~ParseFunction ⇒ <code>Object</code>
Parse function
**Kind**: inner typedef of [<code>ArgumentParser</code>](#module_@zakkudo/argument-parser..ArgumentParser)
**Returns**: <code>Object</code> - An object for the given schema configuration
**Throws**:
- InvalidArgumentError when and argument is malformed
- InvalidSchemaError when an invalid schema type is used for one of the actions and it's referenced
| Param | Type | Description |
| --- | --- | --- |
| argv | <code>Array</code> | The arguments you want to parse |
<a name="module_@zakkudo/argument-parser..ArgumentParser..Schema"></a>
#### ArgumentParser~Schema : <code>Object</code>
The schema configuration for the paramters of the program
**Kind**: inner typedef of [<code>ArgumentParser</code>](#module_@zakkudo/argument-parser..ArgumentParser)
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| type | [<code>Type</code>](#module_@zakkudo/Type..Type) | The type of parameter. One of string, interger, float, or list |
| [typeName] | <code>String</code> | The type name used for display. An example would be a glob, filename, or other more concrete concept. |
| description | <code>String</code> | The description of the |
| [long] | <code>String</code> | The long form of the switch or nothing |
| [short] | <code>String</code> | The short form of the switch or nothing |
<a name="module_@zakkudo/argument-parser..ArgumentParser..Options"></a>
#### ArgumentParser~Options : <code>Object</code>
Argument parser configuration, controling how argumetns are parsed
and how they are shown in help documentation. You must have at least a long
or short switch name set.
**Kind**: inner typedef of [<code>ArgumentParser</code>](#module_@zakkudo/argument-parser..ArgumentParser)
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| name | <code>String</code> | The name of the executable this library is being used in; |
| version | <code>String</code> | A version string that will be shown with the --version switch; |
| description | <code>String</code> | A blurb of text explaining the how's and why's of the program. |
| schema | [<code>Schema</code>](#module_@zakkudo/argument-parser..ArgumentParser..Schema) | The configuration |
| [leftover] | <code>String</code> | The name for the leftover parameters. Without this, leftover parameters will be disallowed. |
<a name="module_@zakkudo/Type"></a>
<a name="module_@zakkudo/Type..Type"></a>
### @zakkudo/Type~Type : <code>enum</code> ⏏
**Kind**: inner enum of [<code>@zakkudo/Type</code>](#module_@zakkudo/Type)
**Read only**: true
**Properties**
| Name | Type | Default | Description |
| --- | --- | --- | --- |
| INTEGER | <code>String</code> | <code>integer</code> | Used for arguments that should be parsed with parseInt. |
| FLOAT | <code>String</code> | <code>float</code> | Used for arguments that should be parsed with parseFloat. |
| STRING | <code>String</code> | <code>string</code> | Used for arguments that should be used as raw string. |
| BOOLEAN | <code>String</code> | <code>boolean</code> | Used for arguments that should be assumed a true boolean when the flag exists. |
| LIST | <code>String</code> | <code>list</code> | Used for arguments that should be split into an array, using ',' as the delimiter. |
5 changes: 5 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
verbose: true,
testURL: 'http://localhost',
};

21 changes: 21 additions & 0 deletions jsdoc.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"source": {
"includePattern": "src/.+\\.js?$",
"include": "src",
"excludePattern": "(test.js|TestHelper.js)$"

},
"sourceType": "module",
"tags": {
"allowUnknownTags": false,
"dictionaries": ["jsdoc", "closure"]
},
"plugins": [
"plugins/markdown"
],
"opts": {
"destination": "./documentation",
"recurse": true,
"encoding": "utf8"
}
}
54 changes: 54 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"name": "@zakkudo/argument-parser",
"version": "0.0.1",
"description": "Make parsing node command line arguments enjoyable.",
"keywords": [
"node",
"arguments",
"args",
"commandline",
"command",
"cli",
"parser"
],
"main": "index.js",
"files": [
"*"
],
"bin": {},
"engines": {
"node": ">=8.0.0"
},
"repository": "github:zakkudo/argument-parser",
"license": "BSD-3-Clause",
"devDependencies": {
"@babel/cli": "^7.2.3",
"@babel/core": "^7.2.2",
"@babel/plugin-transform-classes": "^7.2.2",
"@babel/plugin-transform-runtime": "^7.2.0",
"@babel/preset-env": "^7.0.0",
"babel-core": "^7.0.0-0",
"babel-jest": "^24.0.0",
"babel-plugin-transform-undefined-to-void": "^6.9.4",
"eslint": "^5.12.1",
"eslint-plugin-jasmine": "^2.10.1",
"eslint-plugin-jest": "^22.1.3",
"eslint-plugin-node": "^8.0.1",
"jest": "^24.0.0",
"jest-cli": "^24.0.0",
"jsdoc": "^3.5.5",
"jsdoc-to-markdown": "^4.0.1"
},
"dependencies": {
"@babel/runtime-corejs2": "^7.3.1"
},
"scripts": {
"build": "scripts/build.sh",
"clean": "scripts/clean.sh",
"cover": "scripts/cover.sh",
"document": "scripts/document.sh",
"lint": "scripts/lint.sh",
"deploy": "scripts/deploy.sh",
"test": "scripts/test.sh"
}
}
26 changes: 26 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

set -e

export NODE_ENV="build"

CURRENT_DIR=$(pwd)
PROJECT_DIR=$(git rev-parse --show-toplevel)

cd $PROJECT_DIR

./scripts/clean.sh
./scripts/document.sh

mkdir build

cp package.json build/package.json
cp README.md build/README.md

./node_modules/.bin/babel src \
--out-dir build \
--source-maps inline \
--ignore "src/test.js" \
--ignore "src/*.test.js" \
--verbose \
"$@"
14 changes: 14 additions & 0 deletions scripts/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

set -e

CURRENT_DIR=$(pwd)
PROJECT_DIR=$(git rev-parse --show-toplevel)

cd $PROJECT_DIR

rm -rf build
rm -rf coverage
rm -rf documentation
rm -f jsdoc.*.conf.tmp
rm -f yarn-error.log

0 comments on commit 9ac7a2f

Please sign in to comment.