added old data
This commit is contained in:
1
project2/node_modules/cli/.npmignore
generated
vendored
Normal file
1
project2/node_modules/cli/.npmignore
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
node_modules
|
201
project2/node_modules/cli/README.md
generated
vendored
Normal file
201
project2/node_modules/cli/README.md
generated
vendored
Normal file
@ -0,0 +1,201 @@
|
||||
**cli is a toolkit for rapidly building command line apps - it includes:**
|
||||
|
||||
- Full featured opts/args parser
|
||||
- Plugin support for adding common options and switches
|
||||
- Helper methods for working with input/output and spawning child processes
|
||||
- Output colored/styled messages, [progress bars](https://github.com/chriso/cli/blob/master/examples/progress.js) or [spinners](https://github.com/chriso/cli/blob/master/examples/spinner.js)
|
||||
- Command [auto-completion](https://github.com/chriso/cli/blob/master/examples/command.js) and [glob support](https://github.com/chriso/cli/blob/master/examples/glob.js)
|
||||
|
||||
Install using `npm install cli` or just bundle [cli.js](https://github.com/chriso/cli/raw/master/cli.js) with your app.
|
||||
|
||||
## Example apps
|
||||
|
||||
### sort.js
|
||||
|
||||
```javascript
|
||||
#!/usr/bin/env node
|
||||
require('cli').withStdinLines(function(lines, newline) {
|
||||
this.output(lines.sort().join(newline));
|
||||
});
|
||||
```
|
||||
|
||||
Try it out
|
||||
|
||||
```bash
|
||||
$ ./sort.js < input.txt
|
||||
```
|
||||
|
||||
Let's add support for an `-n` switch to use a numeric sort, and a `-r` switch to reverse output - only 5 extra lines of code (!)
|
||||
|
||||
```javascript
|
||||
var cli = require('cli'), options = cli.parse();
|
||||
|
||||
cli.withStdinLines(function(lines, newline) {
|
||||
lines.sort(!options.n ? null : function(a, b) {
|
||||
return parseInt(a) > parseInt(b);
|
||||
});
|
||||
if (options.r) lines.reverse();
|
||||
this.output(lines.join(newline));
|
||||
});
|
||||
```
|
||||
|
||||
## Command Line Arguments Parser
|
||||
|
||||
cli takes an object as a map for the arguments you wish to parse.
|
||||
Each property/key in the object is the long version of the argument i.e. --file
|
||||
The array associated with it is the options to apply to that argument.
|
||||
|
||||
### Example
|
||||
```javascript
|
||||
cli.parse({
|
||||
file: [ 'f', 'A file to process', 'file', temp.log ], // -f, --file FILE A file to process
|
||||
time: [ 't', 'An access time', 'time', false], // -t, --time TIME An access time
|
||||
work: [ false, 'What kind of work to do', 'string', 'sleep' ] // --work STRING What kind of work to do
|
||||
});
|
||||
```
|
||||
### Explanation of array options
|
||||
|
||||
1. A short name, single letter i.e. -f, or false if no short name is supported for this option
|
||||
2. A description of the option
|
||||
3. The type of object the argument should map too.
|
||||
Below is a list of the return types followed by a description and a list of
|
||||
valid values you can use for this option to get desired type of Object back.
|
||||
- **as-is:** What you enter, is what you get
|
||||
- 'string', 1, true
|
||||
- **int:** Is converted to an Integer wrapped in a Number Object
|
||||
- 'int', 'number', 'num',
|
||||
- 'time', 'seconds', 'secs', 'minutes', 'mins'
|
||||
- 'x', 'n'
|
||||
- **date:** Is converted to a Date Object
|
||||
- 'date', 'datetime', 'date_time'
|
||||
- **float:** Is converted to a Float wrapped in a Number Object
|
||||
- 'float', 'decimal'
|
||||
- **file:** Is converted to a String Object if it is a valid path
|
||||
- 'path', 'file', 'directory', 'dir'
|
||||
- **email:** Converted to a String Object if it is a valid email format
|
||||
- 'email'
|
||||
- **url:** Converted to a String Object if it is a valid URL format
|
||||
- 'url', 'uri', 'domain', 'host'
|
||||
- **ip:** Converted to a String Object if it is a valid IP Address format
|
||||
- 'ip'
|
||||
- **true:** Converted to true if argument is present on command line
|
||||
- 'bool', 'boolean', 'on'
|
||||
- **false:** Converted to false if argument is present on command line
|
||||
- 'false', 'off', false, 0
|
||||
4. A default value for this option if one is not given on the command line
|
||||
|
||||
## Helper methods
|
||||
|
||||
cli has methods that collect stdin (newline is auto-detected as \n or \r\n)
|
||||
|
||||
```javascript
|
||||
cli.withStdin(callback); //callback receives stdin as a string
|
||||
cli.withStdinLines(callback); //callback receives stdin split into an array of lines (lines, newline)
|
||||
```
|
||||
|
||||
cli also has a lower level method for working with input line by line (see [./examples/cat.js](https://github.com/chriso/cli/blob/master/examples/cat.js) for an example).
|
||||
|
||||
```javascript
|
||||
cli.withInput(file, function (line, newline, eof) {
|
||||
if (!eof) {
|
||||
this.output(line + newline);
|
||||
}
|
||||
});
|
||||
```
|
||||
*Note: `file` can be omitted if you want to work with stdin*
|
||||
|
||||
```javascript
|
||||
//cli.toType(object); If a Built-in type, returns the name of the type as a lower cased String
|
||||
cli.toType([]); // 'array'
|
||||
cli.toType(new Date()); // 'date'
|
||||
cli.toType(1); // 'integer'
|
||||
cli.toType(1.1); // 'float'
|
||||
cli.toType(Math); // 'math'
|
||||
cli.toType(/a/); // 'regex'
|
||||
cli.toType(JSON); // 'json'
|
||||
```
|
||||
|
||||
To output a progress bar, call
|
||||
|
||||
```javascript
|
||||
cli.progress(progress); //Where 0 <= progress <= 1
|
||||
```
|
||||
|
||||
To spawn a child process, use
|
||||
|
||||
```javascript
|
||||
cli.exec(cmd, callback); //callback receives the output of the process (split into lines)
|
||||
```
|
||||
|
||||
cli also comes bundled with kof's [node-natives](https://github.com/kof/node-natives) (access with cli.native) and creationix' [stack](https://github.com/creationix/stack) (access with cli.createServer)
|
||||
|
||||
## Plugins
|
||||
|
||||
Plugins are a way of adding common opts and can be enabled using
|
||||
|
||||
```javascript
|
||||
cli.enable(plugin1, [plugin2, ...]); //To disable, use the equivalent disable() method
|
||||
```
|
||||
|
||||
**help** - *enabled by default*
|
||||
|
||||
Adds `-h,--help` to output auto-generated usage information
|
||||
|
||||
**version**
|
||||
|
||||
Adds `-v,--version` to output version information for the app. cli will attempt to locate and parse a nearby *package.json*
|
||||
|
||||
To set your own app name and version, use `cli.setApp(app_name, version)`
|
||||
|
||||
**status**
|
||||
|
||||
Adds options to show/hide the stylized status messages that are output to the console when using one of these methods
|
||||
|
||||
```javascript
|
||||
cli.debug(msg); //Only shown when using --debug
|
||||
cli.error(msg);
|
||||
cli.fatal(msg); //Exits the process after outputting msg
|
||||
cli.info(msg);
|
||||
cli.ok(msg);
|
||||
```
|
||||
|
||||
`-k,--no-color` will omit ANSI color escapes from the output
|
||||
|
||||
**glob** - *requires* `npm install glob`
|
||||
|
||||
Enables glob matching of arguments
|
||||
|
||||
**timeout**
|
||||
|
||||
Adds `-t,--timeout N` to exit the process after N seconds with an error
|
||||
|
||||
**catchall**
|
||||
|
||||
Adds `-c,--catch` to catch and output uncaughtExceptions and resume execution
|
||||
|
||||
*Note: Plugins are automatically disabled if an option or switch of the same name is already defined*
|
||||
|
||||
## LICENSE
|
||||
|
||||
(MIT license)
|
||||
|
||||
Copyright (c) 2010 Chris O'Hara <cohara87@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
1112
project2/node_modules/cli/cli.js
generated
vendored
Normal file
1112
project2/node_modules/cli/cli.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
17
project2/node_modules/cli/examples/cat.js
generated
vendored
Executable file
17
project2/node_modules/cli/examples/cat.js
generated
vendored
Executable file
@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var cli = require('cli');
|
||||
|
||||
var output_file = function (file) {
|
||||
cli.withInput(file, function (line, sep, eof) {
|
||||
if (!eof) {
|
||||
cli.output(line + sep);
|
||||
} else if (cli.args.length) {
|
||||
output_file(cli.args.shift());
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
if (cli.args.length) {
|
||||
output_file(cli.args.shift());
|
||||
}
|
16
project2/node_modules/cli/examples/command.js
generated
vendored
Executable file
16
project2/node_modules/cli/examples/command.js
generated
vendored
Executable file
@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var cli = require('cli');
|
||||
|
||||
//The second (optional) argument of cli.parse() is a command list
|
||||
//Type `./command.js --help` for usage info
|
||||
|
||||
//cli enables auto-completion of commands (similiar to npm), e.g. all of
|
||||
//the following are equivalent and result in "Command is: install":
|
||||
// $ ./command.js install
|
||||
// $ ./command.js inst
|
||||
// $ ./command.js i
|
||||
|
||||
cli.parse(null, ['install', 'test', 'edit', 'remove', 'uninstall', 'ls']);
|
||||
|
||||
console.log('Command is: ' + cli.command);
|
54
project2/node_modules/cli/examples/echo.js
generated
vendored
Executable file
54
project2/node_modules/cli/examples/echo.js
generated
vendored
Executable file
@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/* All of the following commands are equivalent and write `foo\tbar foo` to out.txt
|
||||
$ ./echo.js -n -e --output=out.txt "foo\tbar" "foo"
|
||||
$ ./echo.js --newline --escape --output "out.txt" "foo\tbar" "foo"
|
||||
$ ./echo.js -ne --output=out.txt "foo\tbar" "foo"
|
||||
$ ./echo.js -en --output="out.txt" "foo\tbar" "foo"
|
||||
*/
|
||||
|
||||
var cli = require('cli');
|
||||
|
||||
cli.parse({
|
||||
newline: ['n', 'Do not output the trailing newline'],
|
||||
escape: ['e', 'Enable interpretation of backslash escapes'],
|
||||
separator: ['s', 'Separate arguments using this value', 'string', ' '],
|
||||
output: [false, 'Write to FILE rather than the console', 'file']
|
||||
});
|
||||
|
||||
cli.main(function (args, options) {
|
||||
var output = '', i, j, l, output_stream;
|
||||
|
||||
if (this.argc) {
|
||||
if (options.escape) {
|
||||
var replace = {'\\n':'\n','\\r':'\r','\\t':'\t','\\e':'\e','\\v':'\v','\\f':'\f','\\c':'\c','\\b':'\b','\\a':'\a','\\\\':'\\'};
|
||||
var escape = function (str) {
|
||||
str += '';
|
||||
for (j in replace) {
|
||||
str = str.replace(i, replace[i]);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
for (i = 0, l = this.argc; i < l; i++) {
|
||||
args[i] = escape(args[i]);
|
||||
}
|
||||
options.separator = escape(options.separator);
|
||||
}
|
||||
output += args.join(options.separator);
|
||||
}
|
||||
|
||||
if (!options.newline) {
|
||||
output += '\n';
|
||||
}
|
||||
|
||||
try {
|
||||
if (options.output) {
|
||||
output_stream = this.native.fs.createWriteStream(options.output)
|
||||
} else {
|
||||
output_stream = process.stdout;
|
||||
}
|
||||
output_stream.write(output);
|
||||
} catch (e) {
|
||||
this.fatal('Could not write to output stream');
|
||||
}
|
||||
});
|
6
project2/node_modules/cli/examples/glob.js
generated
vendored
Executable file
6
project2/node_modules/cli/examples/glob.js
generated
vendored
Executable file
@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var cli = require('cli').enable('glob');
|
||||
|
||||
//Running `./glob.js *.js` will output a list of .js files in this directory
|
||||
console.log(cli.args);
|
20
project2/node_modules/cli/examples/long_desc.js
generated
vendored
Executable file
20
project2/node_modules/cli/examples/long_desc.js
generated
vendored
Executable file
@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var cli = require('../');
|
||||
|
||||
//You can (optionally) boost the width of output with:
|
||||
//cli.width = 120;
|
||||
|
||||
//You can also adjust the width of the options/command definitions
|
||||
//cli.option_width = 25;
|
||||
|
||||
var long_desc = 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s '
|
||||
+ 'standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make'
|
||||
+ ' a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, '
|
||||
+ 'remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing '
|
||||
+ 'Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions'
|
||||
+ ' of Lorem Ipsum.';
|
||||
|
||||
cli.parse({
|
||||
foo: ['f', long_desc]
|
||||
});
|
11
project2/node_modules/cli/examples/progress.js
generated
vendored
Executable file
11
project2/node_modules/cli/examples/progress.js
generated
vendored
Executable file
@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var cli = require('cli');
|
||||
|
||||
var i = 0, interval = setInterval(function () {
|
||||
cli.progress(++i / 100);
|
||||
if (i === 100) {
|
||||
clearInterval(interval);
|
||||
cli.ok('Finished!');
|
||||
}
|
||||
}, 50);
|
18
project2/node_modules/cli/examples/sort.js
generated
vendored
Executable file
18
project2/node_modules/cli/examples/sort.js
generated
vendored
Executable file
@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var cli = require('cli');
|
||||
|
||||
var options = cli.parse({
|
||||
numeric: ['n', 'Compare using a numeric sort'],
|
||||
reverse: ['r', 'Reverse the results']
|
||||
});
|
||||
|
||||
cli.withStdinLines(function (lines, newline) {
|
||||
lines.sort(!options.numeric ? null : function (a, b) {
|
||||
return parseInt(a) > parseInt(b);
|
||||
});
|
||||
if (options.reverse) {
|
||||
lines.reverse();
|
||||
}
|
||||
this.output(lines.join(newline));
|
||||
});
|
9
project2/node_modules/cli/examples/spinner.js
generated
vendored
Executable file
9
project2/node_modules/cli/examples/spinner.js
generated
vendored
Executable file
@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var cli = require('cli');
|
||||
|
||||
cli.spinner('Working..');
|
||||
|
||||
setTimeout(function () {
|
||||
cli.spinner('Working.. done!', true); //End the spinner
|
||||
}, 3000);
|
1
project2/node_modules/cli/index.js
generated
vendored
Normal file
1
project2/node_modules/cli/index.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
module.exports = require('./cli');
|
70
project2/node_modules/cli/package.json
generated
vendored
Executable file
70
project2/node_modules/cli/package.json
generated
vendored
Executable file
@ -0,0 +1,70 @@
|
||||
{
|
||||
"_from": "cli@~1.0.0",
|
||||
"_id": "cli@1.0.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-IoF1NPJL+klQw01TLUjsvGIbjBQ=",
|
||||
"_location": "/cli",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "cli@~1.0.0",
|
||||
"name": "cli",
|
||||
"escapedName": "cli",
|
||||
"rawSpec": "~1.0.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "~1.0.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/jshint"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/cli/-/cli-1.0.1.tgz",
|
||||
"_shasum": "22817534f24bfa4950c34d532d48ecbc621b8c14",
|
||||
"_spec": "cli@~1.0.0",
|
||||
"_where": "/home/massiveatoms/Desktop/cs142/project2/node_modules/jshint",
|
||||
"author": {
|
||||
"name": "Chris O'Hara",
|
||||
"email": "cohara87@gmail.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "http://github.com/node-js-libs/cli/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Douglas Meyer"
|
||||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"exit": "0.1.2",
|
||||
"glob": "^7.1.1"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "A tool for rapidly building command line apps",
|
||||
"engines": {
|
||||
"node": ">=0.2.5"
|
||||
},
|
||||
"homepage": "http://github.com/node-js-libs/cli",
|
||||
"keywords": [
|
||||
"cli",
|
||||
"command line",
|
||||
"opts",
|
||||
"parseopt",
|
||||
"opt",
|
||||
"args",
|
||||
"console",
|
||||
"argsparse",
|
||||
"optparse",
|
||||
"autocomplete",
|
||||
"command",
|
||||
"autocompletion"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "cli.js",
|
||||
"name": "cli",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@github.com/node-js-libs/cli.git"
|
||||
},
|
||||
"version": "1.0.1"
|
||||
}
|
Reference in New Issue
Block a user