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

Commit

Permalink
feat: change cli parser (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
joolfe committed Apr 24, 2021
1 parent b846bda commit 2009923
Show file tree
Hide file tree
Showing 6 changed files with 278 additions and 25 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"cSpell.words": [
"execa"
]
}
6 changes: 5 additions & 1 deletion bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@

const p2o = require('./p2o')

p2o.parse(process.argv.slice(2))
p2o.parseAsync()
.catch(err => {
process.exitCode = 1
console.error(err.message)
})
49 changes: 45 additions & 4 deletions bin/p2o.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,54 @@
const yargs = require('yargs')
const { readFileSync } = require('fs')
'use strict'

const { Command, CommanderError } = require('commander')
const { version } = require('../package.json')
const postmanToOpenApi = require('../lib')

/*
const { readFileSync } = require('fs')
*/

// TODO
// - usage move options after collection
// - output should be an option better than an arguments?
// - how to pass options
// - error when colletcion doesnt exist
// - r
// - handle error in a homogeneous way
// - add example usage
// - add test for all code here (less cli i think....)
// - check the input field or should be test inside library?
// - silent option to not return in console the result if we have the file...
// - Add some debug or is not needed?

// Requeriments
// - input file
// - output file or if not just return to can pipe the command?? have think about this.

const program = new Command()

program
.version(version, '-v, --vers', 'output the current version')
.name('p2o')
.usage('<collection> [options]')
.arguments('<collection>')
.description('Transform postman collection to OpenAPI', {
collection: 'Relative path to the Postman collection json file'
})
.option('-f, --file <file>', 'Relative path to the file where result will be saved. If empty result will be returned by cli.')
.option('-o, --options <option>', 'Options object containing the optional parameters for the transformation')
.action(async (collection, options, command) => {
try {
console.log(collection)
const result = await postmanToOpenApi(collection, null, {})
console.info(result)
} catch (err) {
// TODO normalize errors here
throw new Error(err)
}
})

module.exports = program

/*
const parser = yargs
.scriptName('p2o')
.command('$0 <collection> [options]',
Expand Down Expand Up @@ -52,5 +92,6 @@ const parser = yargs
.alias('h', 'help')
module.exports = parser
*/

// p2o ./test/resources/input/v2/SimplePost.json -p ./test/resources/options/info.json
178 changes: 176 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2009923

Please sign in to comment.