From 29f7cf34565b007709a2f10084119fd4aa9fc90e Mon Sep 17 00:00:00 2001 From: John Gee Date: Tue, 21 Dec 2021 17:49:26 +1300 Subject: [PATCH 1/3] Clean up examples: - remove option overwrites - remove array for plain values - flags for flags, values for values --- README.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index eeba977..f579ef2 100644 --- a/README.md +++ b/README.md @@ -98,22 +98,22 @@ const { parseArgs } = require('util') ```js // default -const argv = ['-f', '--foo=a', '--foo', 'b'] +const argv = ['-f', '--foo=a', '--goo', 'b'] const options = {} const { flags, values, positionals } = parseArgs(argv, options) -flags // { f: true, foo: true} -values // { f: [undefined], foo: [undefined] } +flags // { f: true, goo: true } +values // { foo: 'a' } positionals // ['b'] ``` ```js // withValue -const argv = ['-f', '--foo=a', '--foo', 'b'] +const argv = ['-f', '--foo=a', '--goo', 'b'] const options = { - withValue: ['foo'] + withValue: ['goo'] } const { flags, values, positionals } = parseArgs(argv, options) -flags // { f: true, foo: true} -values // { f: [undefined], foo: ['b'] } +flags // { f: true } +values // { foo: 'a', goo: 'b' } positionals // [] ``` ```js @@ -124,19 +124,19 @@ const options = { multiples: ['foo'] } const { flags, values, positionals } = parseArgs(argv, options) -flags // { f: true, foo: true} -values // { f: [undefined], foo: ['a','b'] } +flags // { f: true } +values // { foo: ['a', 'b'] } positionals // [] ``` ```js // shorts -const argv = ['-f', '--foo=a', '--foo', 'b'] +const argv = ['-f'] const options = { short: { f: 'foo' } } const { flags, values, positionals } = parseArgs(argv, options) -flags // { foo: true} -values // { foo: [undefined] } +flags // { foo: true } +values // {} positionals // ['b'] ``` From 9066676b6651be5c5eb5a509257c4868da807f81 Mon Sep 17 00:00:00 2001 From: John Gee Date: Tue, 21 Dec 2021 17:58:08 +1300 Subject: [PATCH 2/3] Rename variable to more conventional name --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f579ef2..f4711ef 100644 --- a/README.md +++ b/README.md @@ -98,22 +98,22 @@ const { parseArgs } = require('util') ```js // default -const argv = ['-f', '--foo=a', '--goo', 'b'] +const argv = ['-f', '--foo=a', '--bar', 'b'] const options = {} const { flags, values, positionals } = parseArgs(argv, options) -flags // { f: true, goo: true } +flags // { f: true, bar: true } values // { foo: 'a' } positionals // ['b'] ``` ```js // withValue -const argv = ['-f', '--foo=a', '--goo', 'b'] +const argv = ['-f', '--foo=a', '--bar', 'b'] const options = { - withValue: ['goo'] + withValue: ['bar'] } const { flags, values, positionals } = parseArgs(argv, options) flags // { f: true } -values // { foo: 'a', goo: 'b' } +values // { foo: 'a', bar: 'b' } positionals // [] ``` ```js From 137002fbccd6e553ab4c4675e3f3ef8d7cad4a4d Mon Sep 17 00:00:00 2001 From: John Gee Date: Wed, 22 Dec 2021 23:01:58 +1300 Subject: [PATCH 3/3] Make "short" example self-consistent --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f4711ef..6169b0d 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ const { parseArgs } = require('util') ``` ```js -// default +// unconfigured const argv = ['-f', '--foo=a', '--bar', 'b'] const options = {} const { flags, values, positionals } = parseArgs(argv, options) @@ -130,7 +130,7 @@ positionals // [] ``` ```js // shorts -const argv = ['-f'] +const argv = ['-f', 'b'] const options = { short: { f: 'foo' } }