diff --git a/README.md b/README.md index 22946e5..8eff1ea 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,16 @@ # wgetjs [![NPM version](https://badge.fury.io/js/wgetjs.png?branch=master)](http://badge.fury.io/js/wgetjs) [![Build Status](https://travis-ci.org/angleman/wgetjs.png?branch=master)](https://travis-ci.org/angleman/wgetjs) [![Dependency Status](https://gemnasium.com/angleman/wgetjs.png?branch=master)](https://gemnasium.com/angleman/wgetjs) [![License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](#licensemit) -Ultra simple async retrieval of remote files over http or https +Ultra simple async retrieval of remote files over http or https inspired by wgetjs ## Install ``` -npm install wgetjs +npm install node-wget ``` ## Usage ```javascript -var wget = require('wgetjs'); +var wget = require('node-wget'); wget(url); @@ -24,7 +24,7 @@ wget({url: url, dry: true}); // dry run, nothing loaded, callback passing parsed ## Examples ```javascript -var wget = require('wgetjs'); +var wget = require('node-wget'); wget('https://raw.github.com/angleman/wgetjs/master/angleman.png'); // angleman.png saved to current folder @@ -58,4 +58,34 @@ wget({ ); ``` +## CLI + +Install: + +```bash +$ npm install -g node-wget +``` + +Use: + +```text +Usage: wget [options] + +Ultra simple async retrieval of remote files over http or https + +Options: + + -h, --help output usage information + -v, --version output version number + -d, --destination specify download destination + +Usage: + +# Download file +$ wget https://github.com/NodeOS/NodeOS/archive/master.zip + +# Download file to location +$ wget https://github.com/NodeOS/NodeOS/archive/master.zip -d path/to/here/ +``` + ## License: MIT diff --git a/cli.js b/cli.js new file mode 100644 index 0000000..abfbd5f --- /dev/null +++ b/cli.js @@ -0,0 +1,99 @@ +#!/usr/bin/env node +'use strict'; + +/* eslint-disable no-process-exit */ + +/* + * Dependencies. + */ + +var wget = require('./'); +var pack = require('./package.json'); + +/* + * Arguments. + */ + +var argv = process.argv.slice(2); + +/* + * Command. + */ + +var command = Object.keys(pack.bin)[0]; + +/** + * Help. + * + * @return {string} + */ +function help() { + return [ + '', + 'Usage: ' + command + ' [options] [url]...', + '', + pack.description, + '', + 'Options:', + '', + ' -h, --help output usage information', + ' -v, --version output version number', + '', + 'Usage:', + '', + '# Download file', + '$ ' + command + ' https://github.com/NodeOS/NodeOS/archive/master.zip', + '' + ].join('\n ') + '\n'; +} + +/* + * Program. + */ + +if ( + argv.indexOf('--help') !== -1 || + argv.indexOf('-h') !== -1 +) { + console.log(help()); +} else if ( + argv.indexOf('--version') !== -1 || + argv.indexOf('-v') !== -1 +) { + console.log(pack.version); +} else if (argv.length) { + var destinationIndex = argv.indexOf('--destination') + argv.indexOf('-d') + 2; + + var args = {}; + if(destinationIndex){ + args.dest = argv[destinationIndex]; + argv.splice(destinationIndex-1,2); + } + args.url = firstNonFlag(argv); + if(args.url.length > 0){ + console.log("Downloading..."); + wget(args, callback); + }else{ + console.log(help()); + } +} else { + console.log(help()); +} + +function callback(error, response, body){ + if(error){ + console.log('--- error:'); + console.log(error); + }else{ + console.log('Done!'); + } +} + +function firstNonFlag(args){ + for(var i = 0; i < args.length; i++){ + if(args[i].charAt(0) != '-'){ + return args[i]; + } + } + return ""; +} diff --git a/package.json b/package.json index 7158d0c..55c973b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "wgetjs", - "version": "0.3.6", + "name": "node-wget", + "version": "0.4.3", "description": "Ultra simple async retrieval of remote files over http or https", "main": "wget.js", "scripts": { @@ -9,7 +9,7 @@ }, "repository": { "type": "git", - "url": "https://github.com/angleman/wgetjs.git" + "url": "https://github.com/tylerl0706/wgetjs.git" }, "keywords": [ "curl", @@ -19,23 +19,26 @@ "http", "https" ], - "author": "angleman", + "author": "tylerl0706", "license": "MIT", "bugs": { - "url": "https://github.com/angleman/wgetjs/issues" + "url": "https://github.com/tylerl0706/wgetjs/issues" }, "engines": { "node": ">=0.8.6" }, + "bin": { + "wget": "cli.js" + }, "dependencies": { - "request": "~2.27.0" + "request": "~2.85.0" }, "devDependencies": { - "license-md": "~0.2.5", - "grunt": "~0.4.1", - "grunt-bump": "~0.0.11", - "grunt-license": "~0.1.4", - "mocha": "~1.12.0", - "should": "~1.2.2" + "license-md": "~0.3.6", + "grunt": "~1.0.2", + "grunt-bump": "~0.8.0", + "grunt-license": "~0.1.5", + "mocha": "~5.0.4", + "should": "~13.2.1" } -} \ No newline at end of file +}