yargs / yargs/yargs

How to use config and pkgConf to configure subcommands?

Open
#858 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement Help Wanted
Dominant language
JavaScript
Stars
11.5k
Forks
1k
PR merge metrics
No merged PRs in 30d

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing yargs subcommand configuration and the pkgConf/package.json integration described in the issue, then compare the related issue #464. Define how separate out-file values for bar and baz should be represented in one config source, and document or implement the agreed behavior with coverage for both subcommands.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.