yargs/yargs

How to use config and pkgConf to configure subcommands?

Open

#858 创建于 2017年4月17日

在 GitHub 查看
 (4 评论) (1 反应) (0 负责人)JavaScript (10,829 star) (1,053 fork)batch import
Help Wantedenhancement

描述

If I have subcommands, how would I go about getting things configured via config file and/or package.json via pkgConf?

For example, let's say I have this:

foo bar --out-file ./bar.txt
foo baz --out-file ./baz.txt

...but now I want to call my subcommands with a single config file (or via package.json) like this:

foo bar --config ./foo.json
foo baz --config ./foo.json

How do I configure the "out-file" option for each subcommand? Won't users run into "namespace" conflicts on my options (i.e. since I can only have one "out-file" key in my config)? How do i specify a separate out-file for both bar and baz without requiring the user to have two different config files (e.g. bar.config and baz.config)? How do I do this with package.json via pkgConf with only a single "foo" key in package.json?

Related issue: https://github.com/yargs/yargs/issues/464

贡献者指南