Skip to content

feat(cli): add --print-default-config and -c/--config with presets and tilde expansion - #46

Open
felipecm-br wants to merge 1 commit into
Blankeos:mainfrom
felipecm-br:feat/cli-config-polish
Open

felipecm-br wants to merge 1 commit into
Blankeos:mainfrom
felipecm-br:feat/cli-config-polish

Conversation

@felipecm-br

Copy link
Copy Markdown
Contributor

Summary

Adds ergonomic CLI configuration flags and improves configuration file discovery:

  • --print-default-config: Prints the full default configuration YAML to stdout and exits (lazygit parity for users bootstrapping their configuration).
  • -c / --config <path>: Enables loading a custom configuration file or preset (e.g. lazygitrs -c popup or lazygitrs -c ~/custom.yml).
  • Tilde (~) Expansion: Expands leading ~ and ~/... using dirs::home_dir().
  • .yaml and .yml Support: Discovers both config.yaml and config.yml across candidate config paths and presets.
  • Informative Error Reporting: Produces a clear bail message if a specified configuration override or preset does not exist.
  • Unit Tests: Full test suite covering CLI flags, tilde expansion, and config loading failure paths.

Verification

  • cargo fmt verified.
  • cargo test --bin lazygitrs (375 passed).

@Blankeos

Blankeos commented Nov 5, 2026 •

Copy link
Copy Markdown
Owner

feat/cli-config-polish → main
Model: claude-sonnet-5-5, effort unknown

Confidence: 4/5

Small, additive, and it works when run. The remaining points are a -c meaning that differs from lazygit, a couple of rough edges in path vs preset resolution, and no docs for the new flags.

Checks run

  • cargo test: 375 passed, 0 failed (includes the 4 new tests). cargo fmt --check: clean. cargo clippy --all-targets: no new warnings in the changed lines.
  • Built a release binary and ran it in a pty with an isolated HOME/XDG dir:
    • --print-default-config exits 0, prints 158 lines, and is deterministic across runs. It doesn't read the user's config (a broken config.yml doesn't affect it). The -c flag is ignored when it's combined.
    • Round trip: --print-default-config > x.yml; lazygitrs -c x.yml starts the TUI fine.
    • -c popup finds presets/popup.yaml or presets/popup.yml (also tested the .yml only case).
    • -c '~/off.yml' is expanded (the shell was not expanding it; a broken file gave the YAML parse error, so the file was read).
    • -c ../rel.yml (relative path) works.
    • config.yaml is discovered when no config.yml exists. When both exist, config.yml wins.
    • Errors: -c /nope.yml → Config file not found at: /nope.yml (exit 1). -c nopreset → Config file or preset not found: 'nopreset' (checked relative, absolute, and presets in <dir>) (exit 1). Invalid YAML → serde error, exit 1. All exit before the TUI opens.
    • Lazygit comparison: lazygit's -c/--config means "print the default config" with no argument. Here lazygitrs -c (no value) gives clap's a value is required for '--config <CONFIG>'.

Summary

Thanks Felipe, this works as described and the error messages are clear. Things I'd tweak:

  1. -c vs lazygit: in lazygit -c prints the default config, and the file flag is -ucf/--use-config-file. Here -c takes a path, so someone typing the lazygit habit gets a clap error rather than output. Not wrong, just a divergence worth a README line, or keep --config long-only and don't claim -c.
  2. Path vs preset ambiguity: a bare name is treated as a path when a file or directory with that name exists in the cwd. lazygitrs -c popup in a folder that has a popup/ directory fails with Is a directory (os error 21) instead of falling back to the preset. -c ~ has the same message. Checking is_file() instead of exists() and adding the path to the error would fix both.
  3. .. in preset names: -c ../evil resolves as a relative path, so it isn't a traversal bug (the user is choosing their own file), but the preset lookup doesn't reject / or .. in names either; only matters if presets are ever resolved from untrusted input.
  4. Docs: the new flags and the presets directory aren't in the README. Also the --print-default-config output has no header or note saying where to put it.

Map

flowchart LR
  cli[main.rs: -c / --print-default-config] --> app[App::new]
  app --> cfg[AppConfig::load]
  cfg --> uc[UserConfig::load]
  uc -->|path / ~ / presets dir| file[config.yml / .yaml / preset]
Loading

Start at UserConfig::load in src/config/user_config.rs.

Regressions

None found. Default startup (no flags) behaves as before; config.yaml is only picked up when no config.yml exists.

Migrations

None.

Before merging

  • Decide on -c vs lazygit (README note, or long-only --config)
  • is_file() instead of exists(), and include the path in the "Is a directory" error
  • README: mention the flags and presets/

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