Skip to content

feat: add --with-config-override CLI flag#1492

Open
youdie006 wants to merge 1 commit into
yorukot:mainfrom
youdie006:feat/config-override-flag
Open

feat: add --with-config-override CLI flag#1492
youdie006 wants to merge 1 commit into
yorukot:mainfrom
youdie006:feat/config-override-flag

Conversation

@youdie006

@youdie006 youdie006 commented Jun 20, 2026

Copy link
Copy Markdown

Description

Adds a repeatable --with-config-override 'key=value' flag (alias --wco) that overrides individual config.toml values from the CLI, as requested in #1272 (modeled on rovr's --with/--without).

ApplyConfigOverrides (new src/internal/common/config_override.go) maps each TOML key to its ConfigType field via the toml:"..." tags — the same reflection approach LoadTomlFile uses — splits on the first = (so values may contain =), and coerces the value by field kind (string / bool / int / []string). It runs after the config file decodes and before ValidateConfig, so overrides are validated like the rest of the config. Unknown keys, a missing =, and unparseable values each return a clear error naming the key.

Example: spf --with-config-override 'debug=true' (repeatable: --wco 'a=1' --wco 'b=2').

Related Issues

Fixes #1272

Screenshots

CLI flag + config behavior (no UI change). Verified manually: --with-config-override 'debug=true' launched the TUI and produced DEBUG-level log entries (none without the override); error paths exit before the TUI with a clear message; the flag appears in --help.

Checklist

  • go fmt (gofmt clean)
  • golangci-lint run — not available in my environment; go vet, go build, and go test ./... pass (only pre-existing env failures: missing exiftool/zoxide binaries)
  • Tested — 15-case unit test for parsing / type coercion / error paths (red->green) plus a runtime smoke test
  • No leftover debug logs

Summary by CodeRabbit

  • New Features

    • Added a repeatable CLI flag --with-config-override (alias --wco) to override configuration values using key=value syntax.
  • Bug Fixes

    • Overrides are now applied right after loading the config file and before validation, avoiding validation against pre-override values.
  • Tests

    • Added unit tests for override parsing/application, including whitespace handling, repeated overrides, and error cases for unknown keys and invalid values.

@github-actions

Copy link
Copy Markdown

🎉 Thank you for your first contribution to superfile!

We’re really excited to have you here 🙌

A maintainer might ask you to make a few changes before we can merge this PR.
That’s totally normal and part of the process. Don’t worry, we’ll help guide you through it.

👉 Please also take a moment to review our Contribution Guide

If you have any questions, feel free to open a Discussion or just ask in the comments!

@github-actions github-actions Bot added test related PR / Issue related to testcases or testing in general. new config labels Jun 20, 2026
@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 296bb2d9-d625-419a-9753-774dd0e079ec

📥 Commits

Reviewing files that changed from the base of the PR and between 001253a and a67a1a7.

📒 Files selected for processing (5)
  • src/cmd/main.go
  • src/config/fixed_variable.go
  • src/internal/common/config_override.go
  • src/internal/common/config_override_test.go
  • src/internal/common/load_config.go
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/cmd/main.go
  • src/internal/common/load_config.go
  • src/config/fixed_variable.go
  • src/internal/common/config_override_test.go
  • src/internal/common/config_override.go

📝 Walkthrough

Walkthrough

Adds a repeatable --with-config-override (--wco) CLI flag that accepts key=value strings. The values are stored in a global ConfigOverrides slice, then applied to the loaded config struct via TOML-tag reflection in a new ApplyConfigOverrides function, which runs after config file load and before validation.

Changes

CLI Config Override Feature

Layer / File(s) Summary
CLI flag definition and global variable wiring
src/cmd/main.go, src/config/fixed_variable.go
Refactors top-level CLI flags into an appFlags() helper and adds the repeatable --with-config-override / --wco StringSliceFlag. Introduces the exported ConfigOverrides []string global variable populated by UpdateVarFromCliArgs from the CLI option.
ApplyConfigOverrides reflection-based implementation
src/internal/common/config_override.go
Implements ApplyConfigOverrides, buildTomlFieldIndex, and setFieldFromString to parse key=value strings, resolve TOML tag names to struct fields via reflection, and set string, bool, signed integer, and []string field values with explicit error returns for unsupported kinds or malformed input.
LoadConfigFile integration and tests
src/internal/common/load_config.go, src/internal/common/config_override_test.go
LoadConfigFile calls ApplyConfigOverrides after file load and before ValidateConfig, exiting with a LipglossError on failure. Tests cover type parsing correctness, = preservation in values, whitespace trimming, multiple overrides, unknown keys, malformed input, and nil override no-ops.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 A flag for the warren, a key and a value,
No more editing TOML just to test something new!
With --wco whiskers, I hop with delight,
Reflection and toml tags, all wired up right.
The config bends gently at my rabbit command~ ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding a new CLI flag for config overrides.
Linked Issues check ✅ Passed The implementation fully addresses issue #1272 by providing the requested --with-config-override flag for CLI-based config overrides during testing.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing the --with-config-override feature; no unrelated modifications are present.
Docstring Coverage ✅ Passed Docstring coverage is 81.82% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ae175affb7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

return fmt.Errorf("invalid config override %q: expected format 'key=value'", override)
}
key = strings.TrimSpace(key)
rawValue = strings.TrimSpace(rawValue)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve whitespace in override values

For string overrides where whitespace is the intended value, this trims the value before assignment; for example, the default config documents Use ' ' for borderless in src/superfile_config/config.toml:141, but --wco 'border_top= ' becomes an empty string here and then fails ValidateConfig because the border is no longer one cell wide. The key can be trimmed, but the raw value should remain intact for string fields so CLI overrides can represent the same values as config.toml.

Useful? React with 👍 / 👎.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/internal/common/config_override.go (1)

72-106: 💤 Low value

Minor comment precision: nil vs empty slice.

The comment on line 93 states "An empty string yields an empty slice rather than [""]", but when raw == "", the code leaves parts as nil (the zero value of []string), not an empty slice []string{}. While nil and empty slices are functionally equivalent in Go (both have length 0, range the same way, and marshal identically), the comment could be more precise.

This is not a functional issue—just a documentation nit.

📝 Optional precision improvement
-		// Comma separated list, mirroring how TOML arrays of strings are written
-		// inline. An empty string yields an empty slice rather than [""].
+		// Comma separated list, mirroring how TOML arrays of strings are written
+		// inline. An empty string yields a nil slice rather than [""].

Or, if you prefer truly empty slices:

-		var parts []string
+		parts := []string{}
 		if raw != "" {
 			parts = strings.Split(raw, ",")
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/internal/common/config_override.go` around lines 72 - 106, The comment in
the setFieldFromString function that states "An empty string yields an empty
slice rather than [""]" is inaccurate. When raw is an empty string, the code
leaves parts as nil (the zero value of []string), not an empty slice. Update
this comment to correctly reflect that an empty string results in a nil slice,
not an empty slice, since the variable parts is never reassigned from its zero
value when the raw string is empty.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/internal/common/config_override.go`:
- Around line 72-106: The comment in the setFieldFromString function that states
"An empty string yields an empty slice rather than [""]" is inaccurate. When raw
is an empty string, the code leaves parts as nil (the zero value of []string),
not an empty slice. Update this comment to correctly reflect that an empty
string results in a nil slice, not an empty slice, since the variable parts is
never reassigned from its zero value when the raw string is empty.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5b305e6b-c72d-4a92-a5cb-f0b0cf91a6e8

📥 Commits

Reviewing files that changed from the base of the PR and between 58bc608 and ae175af.

📒 Files selected for processing (5)
  • src/cmd/main.go
  • src/config/fixed_variable.go
  • src/internal/common/config_override.go
  • src/internal/common/config_override_test.go
  • src/internal/common/load_config.go

@youdie006 youdie006 force-pushed the feat/config-override-flag branch from ae175af to 001253a Compare June 20, 2026 14:00
Add a repeatable --with-config-override 'key=value' flag (alias --wco) that
overrides individual config.toml values from the CLI (yorukot#1272). ApplyConfigOverrides
maps each TOML key to its ConfigType field via the toml tags, splits on the first
=, and coerces the value by field kind (string/bool/int/[]string), running after
the config decodes and before ValidateConfig. Unknown keys, missing =, and
unparseable values each return a clear error naming the key.

Fixes yorukot#1272
@youdie006 youdie006 force-pushed the feat/config-override-flag branch from 001253a to a67a1a7 Compare June 21, 2026 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting pr review new config test related PR / Issue related to testcases or testing in general.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--with-config-override options to provide a config override via cli.

1 participant