Skip to content

Commit

Permalink
chore: update commander, fix breaking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
aldis-ameriks committed Aug 5, 2021
1 parent e98c3f2 commit 72cb7bf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ function parseArray (value) {
}

async function generateSchema (opts) {
const defaultOpts = program.parse([]).opts()
let argv = process.argv
if (process.argv.length === 2) {
// Starting from commander v8, arguments are mandatory.
// We're adding placeholder argument to be able to parse and get the default args.
argv = [...process.argv, '']
}
const defaultOpts = program.parse(argv).opts()
opts = { ...defaultOpts, ...opts }

if (!opts.connection) {
Expand All @@ -60,14 +66,15 @@ async function generateSchema (opts) {

if (require.main === module) {
(async () => {
if (process.argv.length === 2) {
// Calling script without any arguments, so we're showing help and exiting.
program.help()
}

const command = program.parse(process.argv)
const opts = command.opts()
const args = command.args

if (!args || !args.length) {
program.help()
}

opts.connection = args[0]

const result = await generateSchema(opts)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"license": "MIT",
"dependencies": {
"commander": "^7.2.0",
"commander": "^8.1.0",
"postgres": "^2.0.0-beta.4"
},
"devDependencies": {
Expand Down

0 comments on commit 72cb7bf

Please sign in to comment.