rust-cli / rust-cli/config-rs

Searching for configuration file in parent directories

Open
#386 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
3.2k
Forks
265
Avg merge
2h 42m
Merged PRs (30d)
4

Description

I use this pattern to load my config file

      Config::builder()
            .add_source(File::with_name(".myconfig"))
            .build()?
            .try_deserialize::<MyConfig>()

By default this only picks up a config file in the current directory, but I'm hoping to be able to run my program anywhere within a project that has ".myconfig" in the root directory. Is there a preferred way to do this?

My first thought is to successively ConfigBuilder::build in each parent directory up to / every time ConfigError::NotFound occurs; but that seems pretty naive

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 tracing Config::builder, File::with_name, ConfigBuilder::build, and ConfigError::NotFound to understand the current file lookup behavior. Determine how parent-directory discovery should work and what tests or documentation would demonstrate that a .myconfig file is found when running from a project subdirectory.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.