-
Notifications
You must be signed in to change notification settings - Fork 991
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
config file not being loaded #2040
Comments
I believe this is because of the difference between cjs and esm. The config function uses I can confirm that it doesn't work properly: import yargs from 'yargs'
yargs()
.command(
"cmd1",
"cmd1 desc",
(yargs) =>
yargs.option("opt1", {
describe: "opt1 description",
type: "string",
demandOption: true,
})
.config(),
(argv) => {
console.log({ argv });
}
)
.parse("cmd1 --config ./config.json"); Here's my workaround fix: import yargs from 'yargs'
import { createRequire } from "module";
const require = createRequire(import.meta.url);
yargs()
.command(
"cmd1",
"cmd1 desc",
(yargs) =>
yargs.option("opt1", {
describe: "opt1 description",
type: "string",
demandOption: true,
})
.config("settings", require),
(argv) => {
console.log({ argv });
}
)
.parse("cmd1 --settings ./config.json") You can override the default parsing function by passing a callback as the second argument to |
I'll work on a fix for this, so that the |
@jly36963 thanks for digging into this. |
Closing this as fixed by #416 |
Hi, I have a simple program:
And a
config.json
fileBut when I run
It's seems it's not getting the
test
argument from the config."yargs": "^17.2.1"
The text was updated successfully, but these errors were encountered: