File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33var util = require ( 'util' ) ;
44
5- module . exports = function ( opts ) {
5+ module . exports = function ( options ) {
6+ var opts = util . _extend ( {
7+ indent : ' ' ,
8+ short : false ,
9+ verbose : false
10+ } , options ) ;
11+
612 var code = [ ] ;
713
8- code . push ( 'wget --quiet' ) ;
14+ if ( opts . verbose ) {
15+ code . push ( util . format ( 'wget %s' , opts . short ? '-v' : '--verbose' ) ) ;
16+ } else {
17+ code . push ( util . format ( 'wget %s' , opts . short ? '-q' : '--quiet' ) ) ;
18+ }
919
1020 code . push ( util . format ( '--method %s' , this . source . method ) ) ;
1121
@@ -28,9 +38,9 @@ module.exports = function (opts) {
2838 code . push ( '--body-data ' + JSON . stringify ( this . source . postData . text ) ) ;
2939 }
3040
31- code . push ( '--output-document' ) ;
41+ code . push ( opts . short ? '-O' : '--output-document' ) ;
3242
3343 code . push ( util . format ( '- "%s"' , this . source . url ) ) ;
3444
35- return code . join ( ' \\\n ' ) ;
45+ return code . join ( opts . indent !== false ? ' \\\n' + opts . indent : ' ') ;
3646} ;
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ var fixtures = require ( '../fixtures' ) ;
4+ var HTTPSnippet = require ( '../../src' ) ;
5+
6+ require ( 'should' ) ;
7+
8+ describe ( 'wget' , function ( ) {
9+ it ( 'should convert simple request to wget command' , function ( done ) {
10+ var result = new HTTPSnippet ( fixtures . simple ) . wget ( {
11+ indent : false
12+ } ) ;
13+
14+ result . should . be . a . String ;
15+ result . should . eql ( 'wget --quiet --method POST --header "Cookie: bar=baz" --header "Content-Type: application/json" --body-data "{\\"foo\\": \\"bar\\"}" --output-document - "http://httpconsole.com/debug"' ) ;
16+
17+ done ( ) ;
18+ } ) ;
19+
20+ it ( 'should use short options' , function ( done ) {
21+ var result = new HTTPSnippet ( fixtures . simple ) . wget ( {
22+ short : true ,
23+ indent : false
24+ } ) ;
25+
26+ result . should . be . a . String ;
27+ result . should . eql ( 'wget -q --method POST --header "Cookie: bar=baz" --header "Content-Type: application/json" --body-data "{\\"foo\\": \\"bar\\"}" -O - "http://httpconsole.com/debug"' ) ;
28+
29+ done ( ) ;
30+ } ) ;
31+
32+ it ( 'should use custom indentation' , function ( done ) {
33+ var result = new HTTPSnippet ( fixtures . simple ) . wget ( {
34+ indent : '@'
35+ } ) ;
36+
37+ result . should . be . a . String ;
38+ result . replace ( / \\ \n / g, '' ) . should . eql ( 'wget --quiet @--method POST @--header "Cookie: bar=baz" @--header "Content-Type: application/json" @--body-data "{\\"foo\\": \\"bar\\"}" @--output-document @- "http://httpconsole.com/debug"' ) ;
39+
40+ done ( ) ;
41+ } ) ;
42+ } ) ;
You can’t perform that action at this time.
0 commit comments