0

Below is the out I get from the code that is also below.

Question

input and i are both true, as expected, but why isn't project and p?

They are defined that exact same way as input and i.

$ bin/test --input -p           
{ _: [],
  update: false,
  u: false,
  input: true,
  i: true,
  p: '',
  project: '' }

And the code is

'use strict'
var minimist = require('minimist')

module.exports = () => {
var argv = minimist(process.argv.slice(2), {
  string: 'input',
  string: 'project',
  boolean: ['help'],
  boolean: ['update'],
  alias: { i: 'input', h: 'help', p: 'project', u: 'update' },
  unknown: function () { console.log('Unkown argument') }
})

  if (argv.input || argv.i) {
    console.log(argv)
  }

  if (argv.project || argv.p) {
    console.log(argv)
    console.log('p')
  }
Sandra Schlichting
  • 25,050
  • 33
  • 110
  • 162
  • 1
    You cannot have an object with two `.string` properties and two `.boolean` properties. Your linter should have complained about this. – Bergi Apr 27 '20 at 10:35

1 Answers1

1

You cannot have duplicate property names in an object (unfortunately they are allowed, not throwing exceptions any more).

Your current code is equivalent to

var argv = minimist(process.argv.slice(2), {
  string: 'project',
  boolean: ['update'],
  alias: { i: 'input', h: 'help', p: 'project', u: 'update' },
  unknown: function () { console.log('Unkown argument') }
})

where input is not defined as a string parameter but project is.

What you want to write is

var argv = minimist(process.argv.slice(2), {
  string: ['input', 'project'],
  boolean: ['help', 'update'],
  alias: { i: 'input', h: 'help', p: 'project', u: 'update' },
  unknown: function () { console.log('Unkown argument') }
})
Bergi
  • 630,263
  • 148
  • 957
  • 1,375