-
Notifications
You must be signed in to change notification settings - Fork 3
/
pmpact.js
executable file
·51 lines (45 loc) · 1.7 KB
/
pmpact.js
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
#!/usr/bin/env node
const program = require('commander');
const version = require('./package.json').version;
const Application = require('./app/app');
const debug = require('debug')('pmpact:main');
program
.version(version, '-v, --version')
.arguments('<file-or-url>')
.option('-H, --headers <headers>', 'HTTP Headers when the first argument is a url (json format)')
.option('-o, --output <file>', 'Save the Postman Collection to a file')
.action(async (source, cmd) => {
try {
debug('Execute command with:', source, cmd.headers);
console.log(await new Application().parse(source, cmd.headers, cmd.output));
} catch(err) {
console.error(err);
process.exit(1);
}
});
program.on('--help', () => {
console.log('');
console.log(' Examples');
console.log('');
console.log(' Convert a Pact file to a Postman collection:');
console.log('');
console.log(' $ pmpact pact.json');
console.log('');
console.log(' Convert a hosted Pact file to a Postman collection:');
console.log('');
console.log(' $ pmpact http://pact-broker/pact/latest');
console.log('');
console.log(' Save to a file:');
console.log('');
console.log(' $ pmpact pact.json -o postman-collection.json');
console.log('');
console.log(' Convert a hosted Pact file that requires headers to a Postman collection:');
console.log('');
console.log(' $ pmpact http://pact-broker/pact/latest -H \'{"Authorization":"Basic ZFhmbHR5Rk1n..."}\'');
console.log('');
});
program.parse(process.argv);
const NO_COMMAND = program.rawArgs.length < 3;
if (NO_COMMAND) {
program.help();
}