Skip to content

refactor: move shared helpers to their correct files - #181

Open
nathanjcochran wants to merge 4 commits into
mainfrom
nathan/restructure-2
Open

refactor: move shared helpers to their correct files#181
nathanjcochran wants to merge 4 commits into
mainfrom
nathan/restructure-2

Conversation

@nathanjcochran

@nathanjcochran nathanjcochran commented Aug 3, 2026

Copy link
Copy Markdown
Member

Follow-up to #179, addressing review feedback about where shared helpers should live.

The main outcome is a written-down rule for helper placement in CLAUDE.md — place a helper by who calls it, working down the list until one matches:

  1. One command → that command's file.
  2. Several commands in one group → the group file.
  3. Across groups → a named package-level file.
  4. A genuine standalone utility, with no notion of a command → internal/util.
  5. Used by both CLI and MCP → internal/common.

Applying it:

  • New terminal.go for checkStdinIsTTY, readPasswordFromTerminal, and readString.
  • New password.go for the password rotation helpers shared by db connect and service update-password.
  • All shell completion functions now live in completion.go (serviceIDCompletion, configOptionCompletion, mcpGetCompletion), matching how ghost does it.
  • generateSecurePassword moved to internal/util as util.GenerateSecurePassword.
  • read_replica.go and password_recovery.go folded into db_connect.go — both were reachable only from db connect.
  • The service list output chain moved out of service.go into service_list.go, and MCP's ServiceInfo/convertToServiceInfo out of utils.go into service_list.go.

Also fixed two stale .goreleaser.yml references in CLAUDE.md.

As with #179 this is a pure reorganization — every moved declaration is byte-identical to before, verified by diffing declaration text against main. The exceptions are exporting GenerateSecurePassword plus its two call sites, and splitting one var block so the terminal helpers could move independently.

@nathanjcochran
nathanjcochran marked this pull request as ready for review August 3, 2026 21:53
@nathanjcochran nathanjcochran self-assigned this Aug 3, 2026

@Askir Askir 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.

lgtm! Thank you!

Comment thread internal/cmd/password.go
@@ -0,0 +1,81 @@
package cmd

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.

any opinion about giving files like this one that do not contain any actual cli command a different name so they are more easily identifiable (like the _test for the test files)?

E.g. password_util.go or password_helper.go?

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