Skip to content

Commit 020a52d

Browse files
committed
minor clean ups, docs update, syntax clean for bin
1 parent c5f4706 commit 020a52d

4 files changed

Lines changed: 63 additions & 65 deletions

File tree

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
.DS_Store
2-
npm-debug.log
1+
*.log
32
node_modules
43
coverage*

LICENSE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
SOFTWARE.
22-

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# HTTP Snippet [![version][npm-version]][npm-url] [![License][npm-license]][license-url]
22

3-
HTTP Request snippet generator for *many* languages.
3+
HTTP Request snippet generator for *[many](https://github.com/Mashape/httpsnippet/wiki/Targets)* languages & tools.
44

55
Relies on the popular [HAR](http://www.softwareishard.com/blog/har-12-spec/#request) format to import data and describe HTTP calls.
66

@@ -14,8 +14,6 @@ See it in action on companion service: [APIembed](https://apiembed.com/)
1414

1515
## Install
1616

17-
install from source or through [npm](https://www.npmjs.com/):
18-
1917
```shell
2018
# to use in cli
2119
npm install --global httpsnippet
@@ -27,16 +25,18 @@ npm install --save httpsnippet
2725
## Usage
2826

2927
```
30-
Usage: httpsnippet [options] <file>
3128
32-
Options:
29+
Usage: httpsnippet [options] <file>
30+
31+
Options:
32+
33+
-h, --help output usage information
34+
-V, --version output the version number
35+
-t, --target <target> target output
36+
-c, --client [client] target client library
37+
-o, --output <directory> write output to directory
38+
-n, --output-name <name> output file name
3339
34-
-h, --help output usage information
35-
-V, --version output the version number
36-
-t, --target <target> target output
37-
-c, --client [client] target client library
38-
-o, --output <directory> write output to directory
39-
-n, --output-name <name> output file name
4040
```
4141

4242
###### Example

bin/httpsnippet

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,125 @@
11
#!/usr/bin/env node
22

3-
'use strict';
3+
'use strict'
44

5-
var async = require('async');
6-
var chalk = require('chalk');
7-
var cmd = require('commander');
8-
var debug = require('debug')('httpsnippet');
9-
var fs = require('fs');
10-
var HTTPSnippet = require('../src');
11-
var path = require('path');
12-
var pkg = require('../package.json');
5+
var async = require('async')
6+
var chalk = require('chalk')
7+
var cmd = require('commander')
8+
var debug = require('debug')('httpsnippet')
9+
var fs = require('fs')
10+
var HTTPSnippet = require('../src')
11+
var path = require('path')
12+
var pkg = require('../package.json')
1313

1414
cmd
1515
.version(pkg.version)
16-
.usage('[options] <file>')
16+
.usage('[options] <files ...>')
1717
.option('-t, --target <target>', 'target output')
1818
.option('-c, --client [client]', 'target client library')
1919
.option('-o, --output <directory>', 'write output to directory')
2020
.option('-n, --output-name <name>', 'output file name')
21-
.parse(process.argv);
21+
.parse(process.argv)
2222

2323
if (!cmd.args.length || !cmd.target) {
24-
cmd.help();
24+
cmd.help()
2525
}
2626

2727
if (cmd.output) {
28-
var dir = path.resolve(cmd.output);
28+
var dir = path.resolve(cmd.output)
2929

3030
if (!fs.existsSync(dir)) {
31-
fs.mkdirSync(dir);
31+
fs.mkdirSync(dir)
3232
}
3333
}
3434

3535
async.waterfall([
3636
function isFile (next) {
3737
var iterator = function (item, cb) {
38-
cb(fs.statSync(item).isFile());
39-
};
38+
cb(fs.statSync(item).isFile())
39+
}
4040

4141
async.filter(cmd.args, iterator, function (results) {
42-
next(null, results);
43-
});
42+
next(null, results)
43+
})
4444
},
4545

4646
function read (files, next) {
4747
var iterator = function (file, cb) {
48-
fs.readFile(file, cb);
49-
};
48+
fs.readFile(file, cb)
49+
}
5050

5151
async.map(files, iterator, function (err, results) {
52-
next(err, files, results);
53-
});
52+
next(err, files, results)
53+
})
5454
},
5555

5656
function parse (files, buffers, next) {
5757
var iterator = function (buffer, cb) {
5858
try {
59-
cb(null, JSON.parse(buffer));
59+
cb(null, JSON.parse(buffer))
6060
} catch (e) {
61-
debug('failed to parse source json');
62-
cb('failed to parse source json', null);
61+
debug('failed to parse source json')
62+
cb('failed to parse source json', null)
6363
}
64-
};
64+
}
6565

6666
async.map(buffers, iterator, function (err, results) {
67-
next(err, files, results);
68-
});
67+
next(err, files, results)
68+
})
6969
},
7070

7171
function snippet (files, sources, next) {
7272
var iterator = function (source, cb) {
73-
var snippet;
73+
var snippet
7474

7575
try {
76-
snippet = new HTTPSnippet(source);
76+
snippet = new HTTPSnippet(source)
7777
} catch (e) {
78-
debug(e);
78+
debug(e)
7979

80-
return cb(!e[0] ? 'invalid input' : (e[0].field + ' ' + e[0].message), null);
80+
return cb(!e[0] ? 'invalid input' : (e[0].field + ' ' + e[0].message), null)
8181
}
8282

83-
cb(null, snippet.convert(cmd.target, cmd.client));
84-
};
83+
cb(null, snippet.convert(cmd.target, cmd.client))
84+
}
8585

8686
async.map(sources, iterator, function (err, results) {
87-
next(err, files, results);
88-
});
87+
next(err, files, results)
88+
})
8989
},
9090

9191
function writeOutput (files, snippets, next) {
9292
if (cmd.output) {
9393
var iterator = function (file) {
94-
var index = files.indexOf(file);
95-
var name = path.basename(file, path.extname(file));
94+
var index = files.indexOf(file)
95+
var name = path.basename(file, path.extname(file))
9696

9797
var filename = path.format({
9898
dir: dir,
9999
base: name + HTTPSnippet.extname(cmd.target)
100-
});
100+
})
101101

102-
fs.writeFile(filename, snippets[index] + '\n');
103-
};
102+
fs.writeFile(filename, snippets[index] + '\n')
103+
}
104104

105-
async.each(files, iterator);
105+
async.each(files, iterator)
106106
}
107107

108-
next(null, files, snippets);
108+
next(null, files, snippets)
109109
},
110110

111111
function log (files, snippets, next) {
112112
if (!cmd.output) {
113113
var iterator = function (file) {
114-
var index = files.indexOf(file);
115-
console.log('%s:\n%s\n', chalk.cyan.bold.underline(file), snippets[index]);
116-
};
114+
var index = files.indexOf(file)
115+
console.log('%s:\n%s\n', chalk.cyan.bold.underline(file), snippets[index])
116+
}
117117

118-
async.each(files, iterator);
118+
async.each(files, iterator)
119119
}
120120
}
121121
], function (err, result) {
122-
if (err) {
123-
console.log('%s: %s', chalk.red.bold('ERROR'), err);
124-
}
125-
});
122+
if (err) {
123+
console.log('%s: %s', chalk.red.bold('ERROR'), err)
124+
}
125+
})

0 commit comments

Comments
 (0)