Skip to content

Add config search and creation order and set default to ~/.config/lstk/config.toml#43

Open
silv-io wants to merge 2 commits intomainfrom
silv-io/flc-365
Open

Add config search and creation order and set default to ~/.config/lstk/config.toml#43
silv-io wants to merge 2 commits intomainfrom
silv-io/flc-365

Conversation

@silv-io
Copy link
Member

@silv-io silv-io commented Feb 18, 2026

Motivation

While os.UserConfigDir() is the OS-standard location, most developer tools conventionally use ~/.config directly for user-level config. To align lstk with common dev-tool expectations, we now prefer ~/.config/lstk/config.toml by default, and only fall back to os.UserConfigDir()/lstk/config.toml when ~/.config does not exist.

To make the active config source explicit and easier to debug/document, this PR also adds a lstk config path command that prints the resolved config file path.

This also unlocks project-local config support in a predictable way.

  • Lookup order: ./lstk.toml > ~/.config/lstk/config.toml > os.UserConfigDir()/lstk/config.toml
  • Creation order (when no config exists): ~/.config/lstk/config.toml > os.UserConfigDir()/lstk/config.toml (if ~/.config is missing)

Changes

  • Updated config resolution logic to follow the lookup order and creation order I've laid out above
  • ConfigFilePath() now supports side-effect-free path resolution and returns absolute paths.
  • ConfigDir() now reflects the resolved config file directory.
  • Added new command lstk config path to print the resolved configuration file path.
  • Took up earlier suggestion to just make it explicit in a command that it needs the config to make it easier to define side-effect free commands like config path and version
  • Updated tests and docs in CLAUDE.md

Tests

  • Changed the config tests to test for this new order

@silv-io silv-io changed the title Change config search and creation Add config search and creation order and set default to $HOME/.config/lstk/config.toml Feb 18, 2026
@silv-io silv-io changed the title Add config search and creation order and set default to $HOME/.config/lstk/config.toml Add config search and creation order and set default to ~/.config/lstk/config.toml Feb 18, 2026
@silv-io silv-io marked this pull request as ready for review February 18, 2026 16:10
@coderabbitai
Copy link

coderabbitai bot commented Feb 18, 2026

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

This pull request implements a multi-source configuration file lookup system with automatic creation and a new command to query the resolved configuration path. It introduces a formal precedence order (local project config, XDG/user config, OS-specific fallback) and adds initConfig hooks to commands requiring configuration.

Changes

Cohort / File(s) Summary
Documentation
CLAUDE.md
Updated configuration handling documentation with formal lookup order, automatic file creation behavior, and instruction to query resolved config path via lstk config path.
New Configuration Command
cmd/config.go
Added new config command with path subcommand that outputs the resolved configuration file path.
Root Command Configuration
cmd/root.go
Replaced PersistentPreRunE with PreRunE wired to new initConfig helper function; removed conditional bypass for version command.
Commands with Config Initialization
cmd/login.go, cmd/logout.go, cmd/start.go, cmd/stop.go
Added PreRunE: initConfig to each command to ensure configuration is initialized before execution.
Core Configuration Logic
internal/config/config.go
Refactored configuration system to implement multi-source lookup (local project, XDG user config, OS-specific fallback) with automatic file creation; added ResolvedConfigPath() public function and internal path resolution helpers.
Integration Tests
test/integration/config_test.go
Introduced comprehensive tests for config file creation precedence across OS environments, added test scaffolding helpers (runLstk, testEnvWithHome, expectedOSConfigDir, etc.), and replaced polling logic with deterministic assertions.
Test Setup
test/integration/main_test.go
Modified configDir function to first check for ~/.config/lstk directory existence before falling back to OS-specific config directory.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: establishing a config search and creation order with ~/.config/lstk/config.toml as the default, which aligns with the PR's primary objective.
Description check ✅ Passed The description is well-related to the changeset, clearly explaining the motivation, the specific lookup/creation orders, and the key changes made including the new lstk config path command.

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

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch silv-io/flc-365

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

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.

1 participant

Comments