Skip to content
This repository has been archived by the owner on Dec 27, 2024. It is now read-only.

Commit

Permalink
feat: simple cli called p2o
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramesh-X committed Dec 21, 2020
1 parent 30b138c commit a4cea3f
Show file tree
Hide file tree
Showing 4 changed files with 385 additions and 117 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ node_modules/*
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache
.cache

.idea
39 changes: 39 additions & 0 deletions bin/p2o.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env node
const yargs = require('yargs/yargs');
const { hideBin } = require('yargs/helpers');
const postmanToOpenApi = require('../lib/index');
const fs = require('fs');

const args = yargs(hideBin(process.argv))
.usage('$0 output', 'Convert the input file, usually json, ' +
'with Postman collections to OpenAPI by applying the given options file, also json, ' +
'and save as the output file, usually yml.', (yargs) => {
yargs
.positional('output', {
desc: 'Save the output OpenAPI with this name',
type: 'string',
})
.options('i', {
alias: 'input',
demandOption: true,
desc: 'Path to the Postman collection json file',
type: 'string',
})
.options('o', {
alias: 'options',
desc: 'Path to the Options json file',
type: 'string',
})
}).argv;

const json_str = args.options && fs.readFileSync(args.options, 'utf8');
const options = json_str && JSON.parse(json_str);
console.log(`Converting ${args.input} to ${args.output}, with options:\n${json_str || 'NONE'}`);

postmanToOpenApi(args.input, args.output, options)
.then(_ => {
console.log(`Done !`);
})
.catch(err => {
console.log(err);
});
Loading

0 comments on commit a4cea3f

Please sign in to comment.