I am unsure if this belongs here or over in https://github.com/yargs/yargs instead, but I think it's mostly an issue here in the parser.
In any case, I went and wrote a little CLI tool using nodejs and yargs and in particular its .config() mechanism; so far, so good. However, if I pass --config more than once (e.g. --config a.json --config b.json), it dies with the help message and the confusing report Invalid JSON config file: [ './a.json', './b.json' ]. A little brute force shows that that report arises from
|
else if (argv[configKey]) error = Error(__('Invalid JSON config file: %s', configPath)) |
but is, ultimately, because the call to
mixin.resolve on
|
const resolvedConfigPath = mixin.resolve(mixin.cwd(), configPath) |
is, by default, a call to
path.resolve (owing to
) and
path.resolve balks if not given a string as its second argument.
At the very least the error could be more informative (perhaps, "configuration options may be given at most once"), but because it's possible to have multiple .config() directives applied to yargs, and so the machinery tolerates the notion of multiple config files in general, I would prefer to wrap the entirety of
|
try { |
|
let config = null |
|
const resolvedConfigPath = mixin.resolve(mixin.cwd(), configPath) |
|
const resolveConfig = flags.configs[configKey] |
|
|
|
if (typeof resolveConfig === 'function') { |
|
try { |
|
config = resolveConfig(resolvedConfigPath) |
|
} catch (e) { |
|
config = e |
|
} |
|
if (config instanceof Error) { |
|
error = config |
|
return |
|
} |
|
} else { |
|
config = mixin.require(resolvedConfigPath) |
|
} |
|
|
|
setConfigObject(config) |
|
} catch (ex: any) { |
|
// Deno will receive a PermissionDenied error if an attempt is |
|
// made to load config without the --allow-read flag: |
|
if (ex.name === 'PermissionDenied') error = ex |
|
else if (argv[configKey]) error = Error(__('Invalid JSON config file: %s', configPath)) |
|
} |
in a loop to handle the case that
configPath is an array.
I am unsure if this belongs here or over in https://github.com/yargs/yargs instead, but I think it's mostly an issue here in the parser.
In any case, I went and wrote a little CLI tool using
nodejsandyargsand in particular its.config()mechanism; so far, so good. However, if I pass--configmore than once (e.g.--config a.json --config b.json), it dies with the help message and the confusing reportInvalid JSON config file: [ './a.json', './b.json' ]. A little brute force shows that that report arises fromyargs-parser/lib/yargs-parser.ts
Line 688 in 217aa62
mixin.resolveonyargs-parser/lib/yargs-parser.ts
Line 666 in 217aa62
path.resolve(owing toyargs-parser/lib/index.ts
Line 38 in 90f970a
path.resolvebalks if not given a string as its second argument.At the very least the error could be more informative (perhaps, "configuration options may be given at most once"), but because it's possible to have multiple
.config()directives applied toyargs, and so the machinery tolerates the notion of multiple config files in general, I would prefer to wrap the entirety ofyargs-parser/lib/yargs-parser.ts
Lines 664 to 689 in 217aa62
configPathis an array.