-
Notifications
You must be signed in to change notification settings - Fork 121
Description
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
yargs-parser/lib/yargs-parser.ts
Line 688 in 217aa62
else if (argv[configKey]) error = Error(__('Invalid JSON config file: %s', configPath)) |
mixin.resolve
on yargs-parser/lib/yargs-parser.ts
Line 666 in 217aa62
const resolvedConfigPath = mixin.resolve(mixin.cwd(), configPath) |
path.resolve
(owing to Line 38 in 90f970a
resolve, |
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
yargs-parser/lib/yargs-parser.ts
Lines 664 to 689 in 217aa62
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)) | |
} |
configPath
is an array.