Skip to content

Commit 7e0b647

Browse files
committed
new info() method for exposing more info to each traget
1 parent f9ab94d commit 7e0b647

11 files changed

Lines changed: 69 additions & 33 deletions

File tree

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ At the heart of this module is the [HAR Request object](http://www.softwareishar
122122

123123
### Output Targets
124124

125-
output [targets](/src/targets) are simple modules that expose a constructor *(which handles the transformation)* and a utility method `extname` *(used in CLI for writing output into disk)*
125+
output [targets](/src/targets) are simple modules that expose a constructor *(which handles the transformation)* and a utility `info` method
126126

127127
```js
128128
module.exports = function (opts) {
@@ -133,8 +133,14 @@ module.exports = function (opts) {
133133
// return processed output as string
134134
};
135135

136-
module.exports.extname = function () {
137-
// return preferred filename extention
136+
module.exports.info = function () {
137+
// return target info
138+
return {
139+
key: 'node', // target key
140+
ext: '.js', // preferred extension
141+
title: '', // target label
142+
description: '' // target description
143+
}
138144
};
139145
```
140146

bin/httpsnippet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ async.waterfall([
8686

8787
var filename = path.format({
8888
dir: dir,
89-
base: name + HTTPSnippet.extname(cmd.target)
89+
base: name + HTTPSnippet.info(cmd.target).ext
9090
});
9191

9292
fs.writeFile(filename, snippets[index]);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "1.0.0-beta",
2+
"version": "1.0.0-beta.1",
33
"name": "httpsnippet",
44
"description": "HTTP Request snippet generator for *most* languages",
55
"main": "./src/index.js",

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,6 @@ module.exports._targets = function () {
7373
return Object.keys(targets);
7474
};
7575

76-
module.exports.extname = function (lang) {
77-
return targets[lang].extname();
76+
module.exports.info = function (lang) {
77+
return targets[lang].info();
7878
};

src/targets/curl.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ module.exports = function (options) {
4242
return code.join(opts.indent !== false ? ' \\\n' + opts.indent : ' ');
4343
};
4444

45-
module.exports.extname = function () {
46-
return '.sh';
45+
module.exports.info = function () {
46+
return {
47+
key: 'curl',
48+
ext: '.sh',
49+
title: 'cURL',
50+
link: 'http://curl.haxx.se/',
51+
description: 'curl is a command line tool and library for transferring data with URL syntax'
52+
};
4753
};

src/targets/httpie.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ module.exports = function (options) {
105105
return code.join(opts.indent !== false ? ' \\\n' + opts.indent : ' ');
106106
};
107107

108-
module.exports.extname = function () {
109-
return '.sh';
108+
module.exports.info = function () {
109+
return {
110+
key: 'httpie',
111+
ext: '.sh',
112+
title: 'HTTPie',
113+
link: 'http://httpie.org/',
114+
description: 'a CLI, cURL-like tool for humans'
115+
};
110116
};

src/targets/node.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ module.exports = function (options) {
6363
return code.join('\n');
6464
};
6565

66-
module.exports.extname = function () {
67-
return '.js';
66+
module.exports.info = function () {
67+
return {
68+
key: 'node',
69+
ext: '.js',
70+
title: 'Node.JS',
71+
link: 'http://nodejs.org/api/http.html#http_http_request_options_callback',
72+
description: 'Node.js native HTTP interface'
73+
};
6874
};

src/targets/php.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ module.exports = function (options) {
102102
return code.join('\n');
103103
};
104104

105-
module.exports.extname = function () {
106-
return '.php';
105+
module.exports.info = function () {
106+
return {
107+
key: 'php',
108+
ext: '.php',
109+
title: 'PHP',
110+
link: 'http://php.net/manual/en/book.curl.php',
111+
description: 'PHP with libcurl'
112+
};
107113
};

src/targets/wget.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ module.exports = function (options) {
4545
return code.join(opts.indent !== false ? ' \\\n' + opts.indent : ' ');
4646
};
4747

48-
module.exports.extname = function () {
49-
return '.sh';
48+
module.exports.info = function () {
49+
return {
50+
key: 'wget',
51+
ext: '.sh',
52+
title: 'Wget',
53+
link: 'https://www.gnu.org/software/wget/',
54+
description: 'a free software package for retrieving files using HTTP, HTTPS'
55+
};
5056
};

test/extname.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)