Skip to content

refactor(args): make --config an Option instead of a hardcoded default#1584

Open
lazizbekravshanov wants to merge 2 commits into
orhun:mainfrom
lazizbekravshanov:issue-1182-config-option
Open

refactor(args): make --config an Option instead of a hardcoded default#1584
lazizbekravshanov wants to merge 2 commits into
orhun:mainfrom
lazizbekravshanov:issue-1182-config-option

Conversation

@lazizbekravshanov

Copy link
Copy Markdown

Description

Replaces the hardcoded cliff.toml clap default for --config with config: Option<PathBuf>, so an explicitly-supplied --config is distinguishable from automatic discovery.

  • --config no longer advertises [default: cliff.toml] in --help.
  • init_config is simplified to take an Option<&Path> (dropping the if config_path == DEFAULT_CONFIG { … } special-case).

Behavior is intentionally preserved — this is a type/clarity cleanup, not a behavior change:

  • When --config is omitted, resolution falls back to the default file name and keeps the existing discovery order (project cliff.toml → user config directory → manifest → project discovery → built-in default).
  • .config/cliff.toml discovery (feat: support more configuration files #1448) still works.
  • --config <path>, --config <builtin-name> (e.g. detailed), and --init [--config <path>] all behave exactly as before.

Motivation and Context

Follow-up to the discussion in #1182@joshka suggested (and @orhun agreed) that the clap default should be an Option rather than a hardcoded value. This is the minimal cleanup for that.

One open question for you, @orhun: I kept the resolution order identical for safety, which means with --config omitted the implicit cliff.toml is still checked before the user config directory (unchanged behavior). If you'd prefer the None case to route through pure discovery instead (which would slightly change the project-cliff.toml-vs-user-config precedence), I'm happy to do that in a follow-up — just wanted to avoid changing precedence without your sign-off, since you'd mentioned wanting to discuss the clap usage.

How Has This Been Tested?

  • cargo test (workspace): all green.
  • cargo +nightly fmt --all -- --check and cargo clippy --tests -- -D warnings: clean on the changed code.
  • Manual end-to-end on the built binary: implicit cliff.toml, explicit --config custom.toml, .config/cliff.toml discovery, --config detailed (built-in), --init, and --init --config custom.toml — all behave as before; --help no longer shows the default.

Types of Changes

  • Refactor (refactoring production code)
  • Documentation (no code change)

Checklist:

  • My code follows the code style of this project.
  • I have updated the documentation accordingly (if applicable).
  • I have formatted the code with rustfmt.
    • cargo +nightly fmt --all
  • I checked the lints with clippy.
    • cargo clippy --tests --verbose -- -D warnings
  • I have added tests to cover my changes.
  • All new and existing tests passed.
    • cargo test

Replace the `cliff.toml` clap default with `config: Option<PathBuf>` so an
explicitly supplied `--config` is distinguishable from automatic discovery
(follow-up to the orhun#1182 discussion).

Behavior is preserved: when `--config` is omitted, resolution falls back to the
default file name and follows the existing discovery order (project config ->
user config directory -> built-in default), `.config/cliff.toml` discovery still
works, and `--init` still targets cliff.toml. `init_config` is simplified to take
an `Option` accordingly.
@lazizbekravshanov
lazizbekravshanov requested a review from orhun as a code owner July 13, 2026 20:39
@welcome

welcome Bot commented Jul 13, 2026

Copy link
Copy Markdown

Thanks for opening this pull request! Please check out our contributing guidelines! ⛰️

@orhun

orhun commented Jul 14, 2026

Copy link
Copy Markdown
Owner

Hey! Yes, I think we should enable discovery when the --config option is omitted :)

Also, can you update the docs based on this changes?

Per review on orhun#1584: when `--config` is not given, resolve the configuration
purely through discovery — a project `cliff.toml` / `.cliff.toml` /
`.config/cliff.toml` (searched up the directory tree), then the user
configuration directory — instead of front-loading a hardcoded `cliff.toml`.
An explicit `--config` (path or built-in template name) still overrides
discovery. Update the configuration docs accordingly.
@lazizbekravshanov

Copy link
Copy Markdown
Author

Done in 329e753 👍

When --config is omitted, resolution now goes purely through discovery — a project cliff.toml / .cliff.toml / .config/cliff.toml (searched up the directory tree), then the user config directory — instead of front-loading a hardcoded cliff.toml. An explicit --config <path> (or a built-in template name) still overrides discovery.

Also updated the docs (Configuration → File Path). Verified behaviorally: implicit cliff.toml, .config/cliff.toml discovery, explicit --config custom.toml, --config detailed (built-in), --init, and the no-config default. cargo test/clippy/fmt all clean. Thanks for the review!

@lazizbekravshanov

Copy link
Copy Markdown
Author

Hi @orhun — following up on this one 🙂 I implemented the discovery-when---config-is-omitted behaviour you asked for in 329e753 (project cliff.toml / .cliff.toml / .config/cliff.toml searched up the tree, then the user config dir, then manifest, with an explicit --config still overriding), plus the docs update. It's been sitting green since, so just checking whether there's anything else you'd like changed before it can go in — more than happy to adjust.

(The two red checks are infra-only: "Test suite" is the Codecov-upload GPG flake and "Links" is GitLab returning 403s to the CI runner — both fail intermittently on main too. The 106 real checks pass.) Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants