feat: migrate config format to TOML and add CLI management - #515
Merged
Conversation
…and to manage configuration
…ig command documentation
Binary Size Analysis
|
SuperCoolPencil
force-pushed
the
not-json
branch
from
June 24, 2026 05:14
59d4678 to
a903b98
Compare
SuperCoolPencil
force-pushed
the
not-json
branch
2 times, most recently
from
June 24, 2026 05:30
dc010fd to
6cf6030
Compare
SuperCoolPencil
force-pushed
the
not-json
branch
from
June 24, 2026 05:48
6cf6030 to
8b531ec
Compare
SuperCoolPencil
force-pushed
the
not-json
branch
from
June 24, 2026 06:09
fa56253 to
cf5cc38
Compare
… normalization logic
…-prefixing in utils.go
…arate helper functions
… standardize configuration handling
…paths in URL validation
Member
Author
|
All three comments are addressed:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #509
This PR migrates Surge's configuration files from JSON to TOML and introduces a headless
surge configCLI utility.Changes:
settings.jsontosettings.toml. Integratedgo-toml/v2to robustly handle parsing and mapping configurations dynamically without breaking backward compatibility for the older file formats (likekeymap.json).cmd/config.goprovidingsurge config [Category].[Key] [Value]capability.surge configlists all categories, keys, types, values, and human-readable descriptions.ValidateFunclogic ininternal/config/settings.goto properly supportint64assertions introduced by the new TOML parser.SETTINGS.mdandUSAGE.mdto reflect the new TOML formatting and CLI commands.Greptile Summary
This PR migrates Surge's configuration from JSON to TOML using
pelletier/go-toml/v2(already a transitive dependency) and adds a headlesssurge config/surge categoryCLI for viewing and modifying settings without opening the TUI.LoadSettingsparses TOML into amap[string]any, assigns values to typedSettingpointers, then normalizes them viaResolve()before runningValidate(). Atomic writes via temp-file-then-rename preserve data integrity. Legacysettings.jsonusers are warned on first launch.configCmdsupports list/search/get/set/reset/open;categoryCmdadds list/add/remove subcommands. Type-safeSetSettingcovers bool, int, int64, float64, duration, and string types, with accompanying tests.cli_test.gocoversParseConfigPath,GetSetting,SetSetting, andResetSetting;config_test.gocovers integration flows end-to-end; a regression suite guards against silent startup-warning suppression.Confidence Score: 4/5
Safe to merge with minor cleanup; the TOML migration is well-structured and the new CLI is adequately tested.
The core migration logic is sound — TOML round-trips are correct, type normalization via Resolve() handles all coercions, and atomic writes protect against partial writes. Open items from prior review rounds (EDITOR arg-splitting, float64 validator int64 gap) remain unaddressed. New findings are limited to redundant URL validation, unused resources from PersistentPreRun on config subcommands, a missing description parameter in category add, and a potentially flaky test in CI — none affecting production correctness.
internal/config/settings.go (float64 validators missing int64 case from prior review), cmd/config.go (EDITOR arg-splitting still unaddressed), cmd/root.go (pre-validation duplication and PersistentPreRun resource creation for subcommands)
Important Files Changed
Comments Outside Diff (3)
go.mod, line 279 (link)BurntSushi/tomlis already a direct dependency (used ininternal/tui/colors/colors.gofor theme files) and supportsmap[string]anyunmarshaling. Addingpelletier/go-toml/v2for settings parsing means the binary now ships two TOML parsers. Both libraries overlap entirely in purpose. Either useBurntSushi/tomlfor settings as well, or migrate the theme parser togo-toml/v2— keeping both violates the project's lightweight-dependency policy.Rule Used: What: Reject unnecessary dependencies, abstraction... (source)
Prompt To Fix With AI
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
internal/config/settings.go, line 1201-1215 (link)Clone()uses JSON round-trip, changing value types after TOML loadAfter loading from TOML, integer settings are stored as
int64inSetting.Value.json.Marshalserializes them as JSON numbers;json.UnmarshalviaSetting.UnmarshalJSONthen stores them asfloat64. TheResolve[T]helpers handle this, so callers usingResolveare safe. However, any direct type assertion onValue(e.g.,val.(int64)) would panic on a cloned object even if the original loaded correctly. Consider implementingClonein terms ofSaveSettings/LoadSettingswith a temp buffer, or via an explicit field-by-field copy, to keep the type contract consistent after the TOML migration.Prompt To Fix With AI
internal/config/settings.go, line 890-904 (link)float64validators miss theint64case added by this PR's TOML migration.go-toml/v2unmarshals TOML integers (e.g.,slow_worker_threshold = 0) asint64, notfloat64. The validators forSlowWorkerThresholdandSpeedEmaAlphaonly handlefloat64andint, so a TOML-integer value hits thedefaultbranch and returns "invalid type" — silently resetting those settings to defaults. Theintvalidators in this same diff were fixed (addingint64handling), but thefloat64validators were not. Addcase int64: v = float64(actual)to both validators.Prompt To Fix With AI
Reviews (12): Last reviewed commit: "feat: implement shell completion for con..." | Re-trigger Greptile