diff --git a/README.md b/README.md index c5ff5da..77b6396 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,9 @@ [![Coverage][coverage-image]][coverage-url] -> +> > 🚨 THIS REPO IS AN EARLY WIP -- DO NOT USE ... yet 🚨 -> +> Polyfill of future proposal to the [nodejs/tooling](https://github.com/nodejs/tooling) repo for `util.parseArgs()` @@ -86,8 +86,7 @@ process.mainArgs = process.argv.slice(process._exec ? 1 : 2) * `short` {string} (Optional) A single character alias for an option; When appearing one or more times in `args`; Respects the `multiple` configuration * `strict` {Boolean} (Optional) A `Boolean` on wheather or not to throw an error when unknown args are encountered * Returns: {Object} An object having properties: - * `flags` {Object}, having properties and `Boolean` values corresponding to parsed options passed - * `values` {Object}, have properties and `String` values corresponding to parsed options passed + * `values` {Object}, key:value for each option found. Value is a string for string options, or `true` for boolean options, or an array (of strings or booleans) for options configured as `multiple:true`. * `positionals` {string[]}, containing [Positionals][] ---- @@ -103,30 +102,28 @@ const { parseArgs } = require('@pkgjs/parseargs'); const { parseArgs } = require('@pkgjs/parseargs'); const args = ['-f', '--foo=a', '--bar', 'b']; const options = {}; -const { flags, values, positionals } = parseArgs({ args, options }); -// flags = { f: true, bar: true } -// values = { foo: 'a' } +const { values, positionals } = parseArgs({ args, options }); +// values = { f: true, foo: 'a', bar: true } // positionals = ['b'] ``` ```js const { parseArgs } = require('@pkgjs/parseargs'); -// withValue +// type:string const args = ['-f', '--foo=a', '--bar', 'b']; const options = { - foo: { + bar: { type: 'string', }, }; -const { flags, values, positionals } = parseArgs({ args, options }); -// flags = { f: true } -// values = { foo: 'a', bar: 'b' } +const { values, positionals } = parseArgs({ args, options }); +// values = { f: true, foo: 'a', bar: 'b' } // positionals = [] ``` ```js const { parseArgs } = require('@pkgjs/parseargs'); -// withValue & multiple +// type:string & multiple const args = ['-f', '--foo=a', '--foo', 'b']; const options = { foo: { @@ -134,9 +131,8 @@ const options = { multiple: true, }, }; -const { flags, values, positionals } = parseArgs({ args, options }); -// flags = { f: true } -// values = { foo: ['a', 'b'] } +const { values, positionals } = parseArgs({ args, options }); +// values = { f: true, foo: [ 'a', 'b' ] } // positionals = [] ``` @@ -150,9 +146,8 @@ const options = { type: 'boolean' }, }; -const { flags, values, positionals } = parseArgs({ args, options }); -// flags = { foo: true } -// values = {} +const { values, positionals } = parseArgs({ args, options }); +// values = { foo: true } // positionals = ['b'] ``` @@ -190,17 +185,20 @@ const { flags, values, positionals } = parseArgs({ args, options }); - `"0o22"` - Does it coerce types? - no -- Does `--no-foo` coerce to `--foo=false`? For all flags? Only boolean flags? - - no, it sets `{args:{'no-foo': true}}` +- Does `--no-foo` coerce to `--foo=false`? For all options? Only boolean options? + - no, it sets `{values:{'no-foo': true}}` - Is `--foo` the same as `--foo=true`? Only for known booleans? Only at the end? - - no, `--foo` is the same as `--foo=` + - no, they are not the same. There is no special handling of `true` as a value so it is just another string. - Does it read environment variables? Ie, is `FOO=1 cmd` the same as `cmd --foo=1`? - no - Do unknown arguments raise an error? Are they parsed? Are they treated as positional arguments? - no, they are parsed, not treated as positionals -- Does `--` signal the end of flags/options? - - **open question** - - If `--` signals the end, is `--` included as a positional? is `program -- foo` the same as `program foo`? Are both `{positionals:['foo']}`, or is the first one `{positionals:['--', 'foo']}`? +- Does `--` signal the end of options? + - yes +- Is `--` included as a positional? + - no +- Is `program -- foo` the same as `program foo`? + - yes, both store `{positionals:['foo']}` - Does the API specify whether a `--` was present/relevant? - no - Is `-bar` the same as `--bar`? @@ -208,8 +206,8 @@ const { flags, values, positionals } = parseArgs({ args, options }); [Utility Syntax Guidelines in POSIX.1-2017](https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html). `-bar` expands to `-b`, `-a`, `-r`. - Is `---foo` the same as `--foo`? - no - - the first flag would be parsed as `'-foo'` - - the second flag would be parsed as `'foo'` + - the first is a long option named `'-foo'` + - the second is a long option named `'foo'` - Is `-` a positional? ie, `bash some-test.sh | tap -` - yes diff --git a/index.js b/index.js index ac0e78f..f69fba3 100644 --- a/index.js +++ b/index.js @@ -76,27 +76,24 @@ const protoKey = '__proto__'; function storeOptionValue(options, longOption, value, result) { const optionConfig = options[longOption] || {}; - // Flags - result.flags[longOption] = true; - if (longOption === protoKey) { return; } // Values + const usedAsFlag = value === undefined; + const newValue = usedAsFlag ? true : value; if (optionConfig.multiple) { // Always store value in array, including for flags. // result.values[longOption] starts out not present, // first value is added as new array [newValue], // subsequent values are pushed to existing array. - const usedAsFlag = value === undefined; - const newValue = usedAsFlag ? true : value; if (result.values[longOption] !== undefined) ArrayPrototypePush(result.values[longOption], newValue); else result.values[longOption] = [newValue]; } else { - result.values[longOption] = value; + result.values[longOption] = newValue; } } @@ -132,7 +129,6 @@ const parseArgs = ({ ); const result = { - flags: {}, values: {}, positionals: [] }; diff --git a/test/dash.js b/test/dash.js index c727e0a..931b04f 100644 --- a/test/dash.js +++ b/test/dash.js @@ -13,7 +13,7 @@ const { parseArgs } = require('../index.js'); test("dash: when args include '-' used as positional then result has '-' in positionals", (t) => { const passedArgs = ['-']; - const expected = { flags: {}, values: {}, positionals: ['-'] }; + const expected = { values: {}, positionals: ['-'] }; const result = parseArgs({ args: passedArgs }); @@ -25,7 +25,7 @@ test("dash: when args include '-' used as positional then result has '-' in posi test("dash: when args include '-' used as space-separated option value then result has '-' in option value", (t) => { const passedArgs = ['-v', '-']; const passedOptions = { v: { type: 'string' } }; - const expected = { flags: { v: true }, values: { v: '-' }, positionals: [] }; + const expected = { values: { v: '-' }, positionals: [] }; const result = parseArgs({ args: passedArgs, options: passedOptions }); diff --git a/test/index.js b/test/index.js index 2a8f99b..576478d 100644 --- a/test/index.js +++ b/test/index.js @@ -8,7 +8,7 @@ const { parseArgs } = require('../index.js'); test('when short option used as flag then stored as flag', (t) => { const passedArgs = ['-f']; - const expected = { flags: { f: true }, values: { f: undefined }, positionals: [] }; + const expected = { values: { f: true }, positionals: [] }; const args = parseArgs({ args: passedArgs }); t.deepEqual(args, expected); @@ -18,7 +18,7 @@ test('when short option used as flag then stored as flag', (t) => { test('when short option used as flag before positional then stored as flag and positional (and not value)', (t) => { const passedArgs = ['-f', 'bar']; - const expected = { flags: { f: true }, values: { f: undefined }, positionals: [ 'bar' ] }; + const expected = { values: { f: true }, positionals: [ 'bar' ] }; const args = parseArgs({ args: passedArgs }); t.deepEqual(args, expected); @@ -29,7 +29,7 @@ test('when short option used as flag before positional then stored as flag and p test('when short option `type: "string"` used with value then stored as value', (t) => { const passedArgs = ['-f', 'bar']; const passedOptions = { f: { type: 'string' } }; - const expected = { flags: { f: true }, values: { f: 'bar' }, positionals: [] }; + const expected = { values: { f: 'bar' }, positionals: [] }; const args = parseArgs({ args: passedArgs, options: passedOptions }); t.deepEqual(args, expected); @@ -40,7 +40,7 @@ test('when short option `type: "string"` used with value then stored as value', test('when short option listed in short used as flag then long option stored as flag', (t) => { const passedArgs = ['-f']; const passedOptions = { foo: { short: 'f', type: 'boolean' } }; - const expected = { flags: { foo: true }, values: { foo: undefined }, positionals: [] }; + const expected = { values: { foo: true }, positionals: [] }; const args = parseArgs({ args: passedArgs, options: passedOptions }); t.deepEqual(args, expected); @@ -51,7 +51,7 @@ test('when short option listed in short used as flag then long option stored as test('when short option listed in short and long listed in `type: "string"` and used with value then long option stored as value', (t) => { const passedArgs = ['-f', 'bar']; const passedOptions = { foo: { short: 'f', type: 'string' } }; - const expected = { flags: { foo: true }, values: { foo: 'bar' }, positionals: [] }; + const expected = { values: { foo: 'bar' }, positionals: [] }; const args = parseArgs({ args: passedArgs, options: passedOptions }); t.deepEqual(args, expected); @@ -62,7 +62,7 @@ test('when short option listed in short and long listed in `type: "string"` and test('when short option `type: "string"` used without value then stored as flag', (t) => { const passedArgs = ['-f']; const passedOptions = { f: { type: 'string' } }; - const expected = { flags: { f: true }, values: { f: undefined }, positionals: [] }; + const expected = { values: { f: true }, positionals: [] }; const args = parseArgs({ args: passedArgs, options: passedOptions }); t.deepEqual(args, expected); @@ -73,7 +73,7 @@ test('when short option `type: "string"` used without value then stored as flag' test('short option group behaves like multiple short options', (t) => { const passedArgs = ['-rf']; const passedOptions = { }; - const expected = { flags: { r: true, f: true }, values: { r: undefined, f: undefined }, positionals: [] }; + const expected = { values: { r: true, f: true }, positionals: [] }; const args = parseArgs({ args: passedArgs, options: passedOptions }); t.deepEqual(args, expected); @@ -84,7 +84,7 @@ test('short option group behaves like multiple short options', (t) => { test('short option group does not consume subsequent positional', (t) => { const passedArgs = ['-rf', 'foo']; const passedOptions = { }; - const expected = { flags: { r: true, f: true }, values: { r: undefined, f: undefined }, positionals: ['foo'] }; + const expected = { values: { r: true, f: true }, positionals: ['foo'] }; const args = parseArgs({ args: passedArgs, options: passedOptions }); t.deepEqual(args, expected); @@ -95,7 +95,7 @@ test('short option group does not consume subsequent positional', (t) => { test('if terminal of short-option group configured `type: "string"`, subsequent positional is stored', (t) => { const passedArgs = ['-rvf', 'foo']; const passedOptions = { f: { type: 'string' } }; - const expected = { flags: { r: true, f: true, v: true }, values: { r: undefined, v: undefined, f: 'foo' }, positionals: [] }; + const expected = { values: { r: true, v: true, f: 'foo' }, positionals: [] }; const args = parseArgs({ args: passedArgs, options: passedOptions }); t.deepEqual(args, expected); @@ -105,7 +105,7 @@ test('if terminal of short-option group configured `type: "string"`, subsequent test('handles short-option groups in conjunction with long-options', (t) => { const passedArgs = ['-rf', '--foo', 'foo']; const passedOptions = { foo: { type: 'string' } }; - const expected = { flags: { r: true, f: true, foo: true }, values: { r: undefined, f: undefined, foo: 'foo' }, positionals: [] }; + const expected = { values: { r: true, f: true, foo: 'foo' }, positionals: [] }; const args = parseArgs({ args: passedArgs, options: passedOptions }); t.deepEqual(args, expected); @@ -115,7 +115,7 @@ test('handles short-option groups in conjunction with long-options', (t) => { test('handles short-option groups with "short" alias configured', (t) => { const passedArgs = ['-rf']; const passedOptions = { remove: { short: 'r', type: 'boolean' } }; - const expected = { flags: { remove: true, f: true }, values: { remove: undefined, f: undefined }, positionals: [] }; + const expected = { values: { remove: true, f: true }, positionals: [] }; const args = parseArgs({ args: passedArgs, options: passedOptions }); t.deepEqual(args, expected); @@ -124,7 +124,7 @@ test('handles short-option groups with "short" alias configured', (t) => { test('Everything after a bare `--` is considered a positional argument', (t) => { const passedArgs = ['--', 'barepositionals', 'mopositionals']; - const expected = { flags: {}, values: {}, positionals: ['barepositionals', 'mopositionals'] }; + const expected = { values: {}, positionals: ['barepositionals', 'mopositionals'] }; const args = parseArgs({ args: passedArgs }); t.deepEqual(args, expected, 'testing bare positionals'); @@ -134,7 +134,7 @@ test('Everything after a bare `--` is considered a positional argument', (t) => test('args are true', (t) => { const passedArgs = ['--foo', '--bar']; - const expected = { flags: { foo: true, bar: true }, values: { foo: undefined, bar: undefined }, positionals: [] }; + const expected = { values: { foo: true, bar: true }, positionals: [] }; const args = parseArgs({ args: passedArgs }); t.deepEqual(args, expected, 'args are true'); @@ -144,7 +144,7 @@ test('args are true', (t) => { test('arg is true and positional is identified', (t) => { const passedArgs = ['--foo=a', '--foo', 'b']; - const expected = { flags: { foo: true }, values: { foo: undefined }, positionals: ['b'] }; + const expected = { values: { foo: true }, positionals: ['b'] }; const args = parseArgs({ args: passedArgs }); t.deepEqual(args, expected, 'arg is true and positional is identified'); @@ -155,7 +155,7 @@ test('arg is true and positional is identified', (t) => { test('args equals are passed `type: "string"`', (t) => { const passedArgs = ['--so=wat']; const passedOptions = { so: { type: 'string' } }; - const expected = { flags: { so: true }, values: { so: 'wat' }, positionals: [] }; + const expected = { values: { so: 'wat' }, positionals: [] }; const args = parseArgs({ args: passedArgs, options: passedOptions }); t.deepEqual(args, expected, 'arg value is passed'); @@ -165,7 +165,7 @@ test('args equals are passed `type: "string"`', (t) => { test('when args include single dash then result stores dash as positional', (t) => { const passedArgs = ['-']; - const expected = { flags: { }, values: { }, positionals: ['-'] }; + const expected = { values: { }, positionals: ['-'] }; const args = parseArgs({ args: passedArgs }); t.deepEqual(args, expected); @@ -176,7 +176,7 @@ test('when args include single dash then result stores dash as positional', (t) test('zero config args equals are parsed as if `type: "string"`', (t) => { const passedArgs = ['--so=wat']; const passedOptions = { }; - const expected = { flags: { so: true }, values: { so: 'wat' }, positionals: [] }; + const expected = { values: { so: 'wat' }, positionals: [] }; const args = parseArgs({ args: passedArgs, options: passedOptions }); t.deepEqual(args, expected, 'arg value is passed'); @@ -187,7 +187,7 @@ test('zero config args equals are parsed as if `type: "string"`', (t) => { test('same arg is passed twice `type: "string"` and last value is recorded', (t) => { const passedArgs = ['--foo=a', '--foo', 'b']; const passedOptions = { foo: { type: 'string' } }; - const expected = { flags: { foo: true }, values: { foo: 'b' }, positionals: [] }; + const expected = { values: { foo: 'b' }, positionals: [] }; const args = parseArgs({ args: passedArgs, options: passedOptions }); t.deepEqual(args, expected, 'last arg value is passed'); @@ -198,7 +198,7 @@ test('same arg is passed twice `type: "string"` and last value is recorded', (t) test('args equals pass string including more equals', (t) => { const passedArgs = ['--so=wat=bing']; const passedOptions = { so: { type: 'string' } }; - const expected = { flags: { so: true }, values: { so: 'wat=bing' }, positionals: [] }; + const expected = { values: { so: 'wat=bing' }, positionals: [] }; const args = parseArgs({ args: passedArgs, options: passedOptions }); t.deepEqual(args, expected, 'arg value is passed'); @@ -209,7 +209,7 @@ test('args equals pass string including more equals', (t) => { test('first arg passed for `type: "string"` and "multiple" is in array', (t) => { const passedArgs = ['--foo=a']; const passedOptions = { foo: { type: 'string', multiple: true } }; - const expected = { flags: { foo: true }, values: { foo: ['a'] }, positionals: [] }; + const expected = { values: { foo: ['a'] }, positionals: [] }; const args = parseArgs({ args: passedArgs, options: passedOptions }); t.deepEqual(args, expected, 'first multiple in array'); @@ -225,7 +225,7 @@ test('args are passed `type: "string"` and "multiple"', (t) => { multiple: true, }, }; - const expected = { flags: { foo: true }, values: { foo: ['a', 'b'] }, positionals: [] }; + const expected = { values: { foo: ['a', 'b'] }, positionals: [] }; const args = parseArgs({ args: passedArgs, options: passedOptions }); t.deepEqual(args, expected, 'both arg values are passed'); @@ -241,7 +241,7 @@ test('when expecting `multiple:true` boolean option and option used multiple tim multiple: true, }, }; - const expected = { flags: { foo: true }, values: { foo: [true, true] }, positionals: [] }; + const expected = { values: { foo: [true, true] }, positionals: [] }; const args = parseArgs({ args: passedArgs, options: passedOptions }); t.deepEqual(args, expected); @@ -253,7 +253,7 @@ test('order of option and positional does not matter (per README)', function(t) const passedArgs1 = ['--foo=bar', 'baz']; const passedArgs2 = ['baz', '--foo=bar']; const passedOptions = { foo: { type: 'string' } }; - const expected = { flags: { foo: true }, values: { foo: 'bar' }, positionals: ['baz'] }; + const expected = { values: { foo: 'bar' }, positionals: ['baz'] }; t.deepEqual(parseArgs({ args: passedArgs1, options: passedOptions }), expected, 'option then positional'); t.deepEqual(parseArgs({ args: passedArgs2, options: passedOptions }), expected, 'positional then option'); @@ -268,8 +268,7 @@ test('correct default args when use node -p', (t) => { process.execArgv = ['-p', '0']; const result = parseArgs(); - const expected = { flags: { foo: true }, - values: { foo: undefined }, + const expected = { values: { foo: true }, positionals: [] }; t.deepEqual(result, expected); @@ -285,8 +284,7 @@ test('correct default args when use node --print', (t) => { process.execArgv = ['--print', '0']; const result = parseArgs(); - const expected = { flags: { foo: true }, - values: { foo: undefined }, + const expected = { values: { foo: true }, positionals: [] }; t.deepEqual(result, expected); @@ -302,8 +300,7 @@ test('correct default args when use node -e', (t) => { process.execArgv = ['-e', '0']; const result = parseArgs(); - const expected = { flags: { foo: true }, - values: { foo: undefined }, + const expected = { values: { foo: true }, positionals: [] }; t.deepEqual(result, expected); @@ -319,8 +316,7 @@ test('correct default args when use node --eval', (t) => { process.execArgv = ['--eval', '0']; const result = parseArgs(); - const expected = { flags: { foo: true }, - values: { foo: undefined }, + const expected = { values: { foo: true }, positionals: [] }; t.deepEqual(result, expected); @@ -336,8 +332,7 @@ test('correct default args when normal arguments', (t) => { process.execArgv = []; const result = parseArgs(); - const expected = { flags: { foo: true }, - values: { foo: undefined }, + const expected = { values: { foo: true }, positionals: [] }; t.deepEqual(result, expected); @@ -351,8 +346,7 @@ test('excess leading dashes on options are retained', (t) => { const passedArgs = ['---triple']; const passedOptions = { }; const expected = { - flags: { '-triple': true }, - values: { '-triple': undefined }, + values: { '-triple': true }, positionals: [] }; const result = parseArgs({ args: passedArgs, options: passedOptions }); diff --git a/test/prototype-pollution.js b/test/prototype-pollution.js index 83b47e5..0edf48d 100644 --- a/test/prototype-pollution.js +++ b/test/prototype-pollution.js @@ -6,7 +6,7 @@ const { parseArgs } = require('../index.js'); test('should not allow __proto__ key to be set on object', (t) => { const passedArgs = ['--__proto__=hello']; - const expected = { flags: {}, values: {}, positionals: [] }; + const expected = { values: {}, positionals: [] }; const result = parseArgs({ args: passedArgs }); diff --git a/test/short-option-combined-with-value.js b/test/short-option-combined-with-value.js index fd5dfc6..61255b1 100644 --- a/test/short-option-combined-with-value.js +++ b/test/short-option-combined-with-value.js @@ -7,7 +7,7 @@ const { parseArgs } = require('../index.js'); test('when combine string short with plain text then parsed as value', (t) => { const passedArgs = ['-aHELLO']; const passedOptions = { alpha: { short: 'a', type: 'string' } }; - const expected = { flags: { alpha: true }, values: { alpha: 'HELLO' }, positionals: [] }; + const expected = { values: { alpha: 'HELLO' }, positionals: [] }; const result = parseArgs({ args: passedArgs, options: passedOptions }); @@ -18,7 +18,7 @@ test('when combine string short with plain text then parsed as value', (t) => { test('when combine low-config string short with plain text then parsed as value', (t) => { const passedArgs = ['-aHELLO']; const passedOptions = { a: { type: 'string' } }; - const expected = { flags: { a: true }, values: { a: 'HELLO' }, positionals: [] }; + const expected = { values: { a: 'HELLO' }, positionals: [] }; const result = parseArgs({ args: passedArgs, options: passedOptions }); @@ -29,7 +29,7 @@ test('when combine low-config string short with plain text then parsed as value' test('when combine string short with value like short option then parsed as value', (t) => { const passedArgs = ['-a-b']; const passedOptions = { alpha: { short: 'a', type: 'string' } }; - const expected = { flags: { alpha: true }, values: { alpha: '-b' }, positionals: [] }; + const expected = { values: { alpha: '-b' }, positionals: [] }; const result = parseArgs({ args: passedArgs, options: passedOptions }); @@ -40,7 +40,7 @@ test('when combine string short with value like short option then parsed as valu test('when combine string short with value like long option then parsed as value', (t) => { const passedArgs = ['-a--bar']; const passedOptions = { alpha: { short: 'a', type: 'string' } }; - const expected = { flags: { alpha: true }, values: { alpha: '--bar' }, positionals: [] }; + const expected = { values: { alpha: '--bar' }, positionals: [] }; const result = parseArgs({ args: passedArgs, options: passedOptions }); @@ -51,7 +51,7 @@ test('when combine string short with value like long option then parsed as value test('when combine string short with value like negative number then parsed as value', (t) => { const passedArgs = ['-a-5']; const passedOptions = { alpha: { short: 'a', type: 'string' } }; - const expected = { flags: { alpha: true }, values: { alpha: '-5' }, positionals: [] }; + const expected = { values: { alpha: '-5' }, positionals: [] }; const result = parseArgs({ args: passedArgs, options: passedOptions }); @@ -63,8 +63,7 @@ test('when combine string short with value like negative number then parsed as v test('when combine string short with value which matches configured flag then parsed as value', (t) => { const passedArgs = ['-af']; const passedOptions = { alpha: { short: 'a', type: 'string' }, file: { short: 'f', type: 'boolean' } }; - const expected = { flags: { alpha: true }, values: { alpha: 'f' }, positionals: [] }; - + const expected = { values: { alpha: 'f' }, positionals: [] }; const result = parseArgs({ args: passedArgs, options: passedOptions }); t.deepEqual(result, expected); @@ -74,7 +73,7 @@ test('when combine string short with value which matches configured flag then pa test('when combine string short with value including equals then parsed with equals in value', (t) => { const passedArgs = ['-a=5']; const passedOptions = { alpha: { short: 'a', type: 'string' } }; - const expected = { flags: { alpha: true }, values: { alpha: '=5' }, positionals: [] }; + const expected = { values: { alpha: '=5' }, positionals: [] }; const result = parseArgs({ args: passedArgs, options: passedOptions }); diff --git a/test/short-option-groups.js b/test/short-option-groups.js index bff6609..8c24e1a 100644 --- a/test/short-option-groups.js +++ b/test/short-option-groups.js @@ -7,18 +7,7 @@ const { parseArgs } = require('../index.js'); test('when pass zero-config group of booleans then parsed as booleans', (t) => { const passedArgs = ['-rf', 'p']; const passedOptions = { }; - const expected = { flags: { r: true, f: true }, values: { r: undefined, f: undefined }, positionals: ['p'] }; - - const result = parseArgs({ args: passedArgs, options: passedOptions }); - - t.deepEqual(result, expected); - t.end(); -}); - -test('when pass low-config group of booleans then parsed as booleans', (t) => { - const passedArgs = ['-rf', 'p']; - const passedOptions = { r: { type: 'boolean' }, f: { type: 'boolean' } }; - const expected = { flags: { r: true, f: true }, values: { r: undefined, f: undefined }, positionals: ['p'] }; + const expected = { values: { r: true, f: true }, positionals: ['p'] }; const result = parseArgs({ args: passedArgs, options: passedOptions }); @@ -29,7 +18,7 @@ test('when pass low-config group of booleans then parsed as booleans', (t) => { test('when pass full-config group of booleans then parsed as booleans', (t) => { const passedArgs = ['-rf', 'p']; const passedOptions = { r: { type: 'boolean' }, f: { type: 'boolean' } }; - const expected = { flags: { r: true, f: true }, values: { r: undefined, f: undefined }, positionals: ['p'] }; + const expected = { values: { r: true, f: true }, positionals: ['p'] }; const result = parseArgs({ args: passedArgs, options: passedOptions }); @@ -40,7 +29,7 @@ test('when pass full-config group of booleans then parsed as booleans', (t) => { test('when pass group with string option on end then parsed as booleans and string option', (t) => { const passedArgs = ['-rf', 'p']; const passedOptions = { r: { type: 'boolean' }, f: { type: 'string' } }; - const expected = { flags: { r: true, f: true }, values: { r: undefined, f: 'p' }, positionals: [] }; + const expected = { values: { r: true, f: 'p' }, positionals: [] }; const result = parseArgs({ args: passedArgs, options: passedOptions }); @@ -51,7 +40,7 @@ test('when pass group with string option on end then parsed as booleans and stri test('when pass group with string option in middle and strict:false then parsed as booleans and string option with trailing value', (t) => { const passedArgs = ['-afb', 'p']; const passedOptions = { f: { type: 'string' } }; - const expected = { flags: { a: true, f: true }, values: { a: undefined, f: 'b' }, positionals: ['p'] }; + const expected = { values: { a: true, f: 'b' }, positionals: ['p'] }; const result = parseArgs({ args: passedArgs, options: passedOptions, strict: false });