1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55/**
* @description
* HTTP code snippet generator for the Shell using Wget.
*
* @author
* @AhmadNassri
*
* for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
*/
'use strict'
const util = require('util')
const helpers = require('../../helpers/shell')
const CodeBuilder = require('../../helpers/code-builder')
module.exports = function (source, options) {
const opts = Object.assign({
indent: ' ',
short: false,
verbose: false
}, options)
const code = new CodeBuilder(opts.indent, opts.indent !== false ? ' \\\n' + opts.indent : ' ')
if (opts.verbose) {
code.push('wget %s', opts.short ? '-v' : '--verbose')
} else {
code.push('wget %s', opts.short ? '-q' : '--quiet')
}
code.push('--method %s', helpers.quote(source.method))
Object.keys(source.allHeaders).forEach(function (key) {
const header = util.format('%s: %s', key, source.allHeaders[key])
code.push('--header %s', helpers.quote(header))
})
if (source.postData.text) {
code.push('--body-data ' + helpers.escape(helpers.quote(source.postData.text)))
}
code.push(opts.short ? '-O' : '--output-document')
.push('- %s', helpers.quote(source.fullUrl))
return code.join()
}
module.exports.info = {
key: 'wget',
title: 'Wget',
link: 'https://www.gnu.org/software/wget/',
description: 'a free software package for retrieving files using HTTP, HTTPS'
}