Skip to content

Add an opts.array #65

Open
Open
@shadowspawn

Description

An issue from the original Minimist repo from @stevendesu with 11 upvotes

https://web.archive.org/web/20200904203616/https://github.com/substack/minimist/issues/136/


I have a command line argument that I wish to always be an array, but it may only contain one value:

Current Behavior

const argv = require("minimist")(process.argv.slice(2), {
    alias: {
        "distributions": ["d"]
    }
});

console.log(argv);
$> node ./index.js -d one -d two
{ _: [],
  distributions: ['one', 'two'],
  d: ['one', 'two']
}
$> node ./index.js -d one
{ _: [],
  distributions: 'one',
  d: 'one'
}

Desired New Option

const argv = require("minimist")(process.argv.slice(2), {
    array: ["distributions"], // <-----------------------------------
    alias: {
        "distributions": ["d"]
    }
});

console.log(argv);
$> node ./index.js -d one
{ _: [],
  distributions: ['one'],
  d: ['one']
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions