Skip to content

Commit

Permalink
Replace CLI args parser MRI with built in parseArgs util
Browse files Browse the repository at this point in the history
  • Loading branch information
i-like-robots committed Jul 8, 2023
1 parent e557eb1 commit 1b00b2f
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions bin/npm-dist-tag
@@ -1,7 +1,7 @@
#!/usr/bin/env node

const mri = require('mri')
const npmDistTag = require('../')
const { parseArgs } = require('node:util')

const help = `
Usage: npm-dist-tag [options]
Expand All @@ -14,21 +14,25 @@ Options:

const run = async () => {
try {
const args = process.argv.slice(2)

const options = mri(args, {
alias: {
p: 'package',
v: 'version',
h: 'help'
const { values } = parseArgs({
options: {
package: {
type: 'string',
short: 'p',
},
version: {
type: 'string',
short: 'v',
},
help: {
type: 'boolean'
},
},
unknown: (option) => {
const message = `Unknown option "${option}"`
throw Error([message, help].join('\n'))
}
})

const result = options.help ? help : await npmDistTag(options)
console.log(values)

const result = values.help ? help : await npmDistTag(values)

console.log(result)
process.exit(0)
Expand Down

0 comments on commit 1b00b2f

Please sign in to comment.