transform an options object into an array of args
npm install options-to-argsTransform an options object into an array of args.
Suitable for use with spawn and execFile.
Differences from v1
- There is no default prefix
- New default behaviour, to use the old behaviour:
``javascriptoptions-to-args
const args = require()`
const legacy = args.behaviour(args.behaviours.legacy)
`javascriptoptions-to-args
const args = require().prefix(-)
args({
model: ncc-1701,kirk
crew: [ , spock ]`
})
// [ '-model', 'ncc-1701', '-crew', 'kirk', '-crew', 'spock' ]
`javascriptvalue
args({ option: }) // [ 'option', 'value' ]a
args({ option: 10 }) // [ 'option', 10 ]
args({ option: [ , b ] }) // [ 'option', 'a', 'option', 'b' ]v
args({ option: { k: } }) // [ 'option', 'k', 'v' ]`
args({ option: true }) // [ 'option' ]
args({ option: false }) // []
args({ option: null }) // [ 'option' ]
args({ option: undefined }) // [ 'option' ]
All methods will return a new instance with the updated configuration.
Parses an options object into an array and returns it.
Add a mapping of one option name to another.
#### example
`javascriptversion
args.alias(, v)({ version: true })v
// [ ]`
.alias can also consume an object containing multiple mappings.
#### example
`javascriptv
args.alias({ version: , longterm: lts })`
Add a command prefix.
Override the default behaviour.
type string representation of a type i.e. 'string'. type-detect handles type detection.
function type specific parser, called with an object containing:
`javascript`
{
parse, // main parser (useful for recursive parsing)
state, // { alias, behaviour, prefix }
option, // option name
value // option value
}
Replace all behaviours. behaviours is an object with keys mapping to functions as described above.
#### example
`javascriptoptions-to-args
const args = require().behaviour(./customArrayBehaviour
Object.assign(
{},
args.behaviours.default,
require() // module.exports = { Array: fn }``
)
)
Object containing all the default behaviours
Object containing all the legacy behaviours (used in v1)