Skip to content

Commit 81899d0

Browse files
authored
Adds header under the promo containing the original curl command (#35)
1 parent a8cb21a commit 81899d0

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

resources/js/curl-to-go.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ function curlToGo(curl) {
1111
var err = 'if err != nil {\n\t// handle err\n}\n';
1212
var deferClose = 'defer resp.Body.Close()\n';
1313
var promo = "// Generated by curl-to-Go: https://mholt.github.io/curl-to-go";
14+
var originalCmd = `// Original command: ${curl}`;
15+
var header = `${promo}\n${originalCmd}\n`;
1416

1517
// List of curl flags that are boolean typed; this helps with parsing
1618
// a command like `curl -abc value` to know whether 'value' belongs to '-c'
@@ -42,9 +44,9 @@ function curlToGo(curl) {
4244
var req = extractRelevantPieces(cmd);
4345

4446
if (Object.keys(req.headers).length == 0 && !req.data.ascii && !req.data.files && !req.basicauth && !req.insecure) {
45-
return promo+"\n"+renderSimple(req.method, req.url);
47+
return header+renderSimple(req.method, req.url);
4648
} else {
47-
return promo+"\n\n"+renderComplex(req);
49+
return header+"\n"+renderComplex(req);
4850
}
4951

5052

0 commit comments

Comments
 (0)