yargs/yargs

How to use config and pkgConf to configure subcommands?

Open

#858 opened on Apr 17, 2017

View on GitHub
 (4 comments) (1 reaction) (0 assignees)JavaScript (10,829 stars) (1,053 forks)batch import
Help Wantedenhancement

Description

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

Contributor guide