Skip to content

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

Merged
silv-io merged 9 commits intomainfrom
silv-io/flc-365
Feb 20, 2026
Merged

Add config search and creation order and set default to ~/.config/lstk/config.toml#43
silv-io merged 9 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 force-pushed the silv-io/flc-365 branch 2 times, most recently from 2a3e5a7 to 8a66cef Compare February 18, 2026 15:53
@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

Implements prioritized config lookup (project-local, XDG, OS), deterministic creation when missing, exposes lstk config path, and wires initConfig (env + config init) as PreRunE for commands that require configuration.

Changes

Cohort / File(s) Summary
Docs
CLAUDE.md, README.md
Document config lookup order, auto-creation policy, env var guidance (including LOCALSTACK_AUTH_TOKEN), and add lstk config path.
CLI: config command
cmd/config.go
Add config command with path subcommand that prints resolved config path.
CLI: command wiring
cmd/root.go, cmd/login.go, cmd/logout.go, cmd/start.go, cmd/stop.go, cmd/logs.go
Replace PersistentPreRunE with initConfig and add PreRunE: initConfig to commands that require config.
Core config logic
internal/config/config.go, internal/config/paths.go, internal/config/containers.go
Refactor config Init/Get to search ordered paths, create config deterministically if missing, add path-resolution helpers, and introduce ContainerConfig/EmulatorType with image/name/health helpers.
Tests
test/integration/config_test.go, test/integration/main_test.go
Add integration tests and helpers for config precedence, creation behavior, and config path command; prefer ~/.config/lstk when present.
Manifest
go.mod
Module file updated (minor).

Sequence Diagram(s)

sequenceDiagram
    participant CLI as "lstk CLI"
    participant Init as "initConfig (env.Init + config.Init)"
    participant ConfigPkg as "internal/config"
    participant FS as "Filesystem"

    CLI->>Init: command invoked (PreRunE)
    Init->>ConfigPkg: env.Init()
    Init->>ConfigPkg: config.Init()
    ConfigPkg->>FS: firstExistingConfigPath() (local, XDG, OS)
    alt config exists
        FS-->>ConfigPkg: return existing path
        ConfigPkg-->>CLI: resolved path available
    else config missing
        ConfigPkg->>FS: compute creation dir (prefer ~/.config if exists)
        ConfigPkg->>FS: write default config file
        FS-->>ConfigPkg: confirm write
        ConfigPkg-->>CLI: resolved path available
    end
    CLI->>CLI: Run command logic (RunE)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: updating config search/creation order with a new default path. It is specific, concise, and reflects the core objective.
Description check ✅ Passed The description is detailed and directly related to the changeset, explaining motivation, lookup/creation order, changes made, and testing approach.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@internal/config/containers.go`:
- Line 44: Remove the redundant comment above the Name function; it simply
restates what the function signature and implementation already convey. Locate
the Name(...) method (the container name builder) in
internal/config/containers.go and delete the line comment that explains the
return format ("localstack-{type}" or "localstack-{type}-{tag}" if tag !=
latest), leaving the function and its implementation intact.

@silv-io silv-io merged commit d2fe0df into main Feb 20, 2026
8 checks passed
@silv-io silv-io deleted the silv-io/flc-365 branch February 20, 2026 11:34
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

Comments