Skip to content

Add self config commands#373

Merged
kindermax merged 2 commits into
masterfrom
self-config
Jun 14, 2026
Merged

Add self config commands#373
kindermax merged 2 commits into
masterfrom
self-config

Conversation

@kindermax

@kindermax kindermax commented Jun 14, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • add lets self config path to print the user settings path
  • add lets self config edit to open the user settings file in nvim
  • document the commands and add tests

Tests

  • go test ./...
  • lets lint

Closes #370

Summary by Sourcery

Add CLI subcommands under lets self config to manage the per-user settings file, including printing its path and opening it in an editor.

New Features:

  • Introduce lets self config path to print the resolved user settings file path.
  • Introduce lets self config edit to open the user settings file in the configured editor.

Enhancements:

  • Refactor self command initialization to inject an editor-opening function for improved testability.

Documentation:

  • Document the new lets self config path and lets self config edit commands in the settings docs and changelog.

Tests:

  • Add tests covering the new self config path and edit commands, including editor invocation and resolved path.

@sourcery-ai

sourcery-ai Bot commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Adds lets self config path and lets self config edit subcommands under self config to manage the per-user settings file, wires them into the CLI, implements an editor helper, and documents and tests the new behavior.

Sequence diagram for lets self config edit command

sequenceDiagram
    actor User
    participant RootCmd
    participant SelfCmd
    participant ConfigCmd
    participant Util
    participant OS

    User->>RootCmd: lets self config edit
    RootCmd->>SelfCmd: Execute self
    SelfCmd->>ConfigCmd: Execute config edit
    ConfigCmd->>Util: LetsUserFile(config.yaml)
    Util-->>ConfigCmd: path
    ConfigCmd->>OS: MkdirAll(config_dir)
    OS-->>ConfigCmd: result
    ConfigCmd->>Util: OpenEditor(path)
    Util-->>ConfigCmd: result
    ConfigCmd-->>User: Config opened in EDITOR
Loading

File-Level Changes

Change Details Files
Add self config command group with path and edit subcommands for managing the per-user config file.
  • Introduce initConfigCommand, initConfigPathCommand, and initConfigEditCommand to encapsulate user config operations.
  • Implement path to resolve config.yaml via util.LetsUserFile and print the resulting path to stdout.
  • Implement edit to resolve config.yaml, ensure its directory exists with os.MkdirAll, and open it using an injected editor function, wrapping errors with context.
internal/cmd/self_config.go
Wire the new config commands into the existing self command while making the editor invocation testable.
  • Refactor initSelfCmd to delegate to a new initSelfCmdWithEditor that accepts an openEditor function.
  • Register the new self config command within initSelfCmdWithEditor using util.OpenEditor in production.
  • Keep existing self subcommands (doc, lsp, skills) intact while extending the command tree.
internal/cmd/self.go
Provide an implementation for opening files in the user’s editor based on the EDITOR environment variable.
  • Add util.OpenEditor which reads $EDITOR, errors if unset, and runs it with the target path using exec.Command.
  • Wire the editor process’s stdin/stdout/stderr to the current process to provide an interactive editing experience.
  • Wrap command execution errors with the editor name for clearer diagnostics.
internal/util/editor.go
Add tests covering the new self config behavior and update documentation and changelog entries.
  • Extend TestSelfCmd to verify self config path prints the expected config path based on HOME.
  • Extend TestSelfCmd to verify self config edit invokes the injected editor callback with the correct config path.
  • Document lets self config path and lets self config edit in settings documentation and note the addition in the changelog.
internal/cmd/root_test.go
docs/docs/settings.md
docs/docs/changelog.md

Assessment against linked issues

Issue Objective Addressed Explanation
#370 Add a lets self config edit command that opens the user config file in the user's EDITOR.
#370 Add a lets self config path command that prints the path to the user config file.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai 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.

Hey - I've found 2 issues, and left some high level feedback:

  • The user config filename config.yaml is hard-coded in multiple places (both commands and tests); consider centralizing this as a constant or helper in one place to avoid divergence if the name ever changes.
  • The Long help text in initConfigCommand hard-codes ~/.config/lets/config.yaml, while the actual path is resolved via util.LetsUserFile; it would be more robust to derive the path from the same helper to keep the help text in sync with the real behavior.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The user config filename `config.yaml` is hard-coded in multiple places (both commands and tests); consider centralizing this as a constant or helper in one place to avoid divergence if the name ever changes.
- The `Long` help text in `initConfigCommand` hard-codes `~/.config/lets/config.yaml`, while the actual path is resolved via `util.LetsUserFile`; it would be more robust to derive the path from the same helper to keep the help text in sync with the real behavior.

## Individual Comments

### Comment 1
<location path="internal/util/editor.go" line_range="10-16" />
<code_context>
+	"os/exec"
+)
+
+func OpenEditor(path string) error {
+	editor := os.Getenv("EDITOR")
+	if editor == "" {
+		return errors.New("EDITOR is not set")
+	}
+
+	cmd := exec.Command(editor, path) //nolint:gosec
+	cmd.Stdin = os.Stdin
+	cmd.Stdout = os.Stdout
</code_context>
<issue_to_address>
**issue (bug_risk):** EDITOR values containing arguments (e.g. "vim -u ...") will not work with exec.Command as used here.

Many users configure EDITOR with flags or spaces in the path (e.g. `code --wait`, `vim -u ~/.vimrc`). `exec.Command(editor, path)` treats the entire EDITOR value as the binary name and doesn’t split arguments, so these setups will fail. Consider either parsing EDITOR into binary + args and appending `path`, or invoking via a shell (e.g. `exec.Command("sh", "-c", editor+" "+shellQuote(path))`).
</issue_to_address>

### Comment 2
<location path="internal/cmd/self_config.go" line_range="62" />
<code_context>
+		Use:   "path",
+		Short: "Print lets user config path",
+		Args:  cobra.NoArgs,
+		RunE: func(cmd *cobra.Command, args []string) error {
+			path, err := util.LetsUserFile("config.yaml")
+			if err != nil {
+				return err
+			}
+
+			_, err = fmt.Fprintln(cmd.OutOrStdout(), path)
+
+			return err
+		},
+	}
+}
+
+func initConfigEditCommand(openEditor func(string) error) *cobra.Command {
+	return &cobra.Command{
+		Use:   "edit",
+		Short: "Open lets user config in EDITOR",
+		Args:  cobra.NoArgs,
+		RunE: func(cmd *cobra.Command, args []string) error {
+			path, err := util.LetsUserFile("config.yaml")
+			if err != nil {
+				return err
+			}
+
+			if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
+				return fmt.Errorf("creating config directory: %w", err)
+			}
</code_context>
<issue_to_address>
**🚨 suggestion (security):** The config directory permissions (0755) might be too permissive for potentially sensitive user configuration.

`0o755` allows group/others to read and traverse the directory. If this config may hold tokens or credentials, defaulting to `0o700` is safer and aligns with typical per-user config directories. Please restrict permissions unless there’s a concrete need for broader access.

```suggestion
			if err := os.MkdirAll(filepath.Dir(path), 0o700); err != nil {
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread internal/util/editor.go
Comment on lines +10 to +16
func OpenEditor(path string) error {
editor := os.Getenv("EDITOR")
if editor == "" {
return errors.New("EDITOR is not set")
}

cmd := exec.Command(editor, path) //nolint:gosec

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.

issue (bug_risk): EDITOR values containing arguments (e.g. "vim -u ...") will not work with exec.Command as used here.

Many users configure EDITOR with flags or spaces in the path (e.g. code --wait, vim -u ~/.vimrc). exec.Command(editor, path) treats the entire EDITOR value as the binary name and doesn’t split arguments, so these setups will fail. Consider either parsing EDITOR into binary + args and appending path, or invoking via a shell (e.g. exec.Command("sh", "-c", editor+" "+shellQuote(path))).

Comment thread internal/cmd/self_config.go Outdated
@kindermax kindermax merged commit 1c97e2a into master Jun 14, 2026
5 checks passed
@kindermax kindermax deleted the self-config branch June 14, 2026 16:44
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.

add lets self config edit command

1 participant