Repo-wide conventions for Go commands under cmd/.
This is the default pattern for new Go commands and the target pattern when existing Go commands are touched.
- Use
github.com/alecthomas/kongfor CLI parsing and help - Use Bubble Tea v2 for TUIs:
charm.land/bubbletea/v2 - When a TUI needs common components or styling, stay on the v2 line:
charm.land/bubbles/v2charm.land/lipgloss/v2
- Put user-facing binaries in
cmd/<name>/ - Put command-local Go logic with the command in
cmd/<name>/ - Use root
internal/only for code shared by multiple commands
- Kong gives nested subcommand help by default, which is a better fit than the current hand-rolled parsing in
cmd/toolbox - Bubble Tea v2 is already in use for
ghrelandssm-connect - One repo-wide pattern makes new tools easier to add and older tools easier to migrate
For non-TUI commands, prefer:
cmd/<name>/main.gofor wiring and process exit- A typed Kong CLI struct for commands, flags, args, and help text
- Small package-local files for behavior split by concern
- Keep single-command helpers in
cmd/<name>/orcmd/<name>/internal/ - Promote code to root
internal/only when it is genuinely shared across commands
For TUIs, prefer:
- Kong for top-level flags and startup validation
- A
newModel(...)constructor - Bubble Tea v2 for the interactive program lifecycle
- Separate files for config, data loading, and TUI model/update/view logic
- Every Go CLI should provide
--help - Nested subcommands should also provide context-sensitive help
- Use Kong help text rather than hand-built help strings where practical
- Command names stay user-facing and kebab-case
- Prefer long flags in kebab-case, for example
--force-refresh - Only add short flags when they are common and obvious
- If a command is not a TUI, prefer
Run() errormethods on Kong command structs
- Primary command output goes to stdout
- Errors and warnings go to stderr
- Error messages should be short and concrete
- Prefer command-prefixed errors when context matters, for example
ssm-connect: AWS region is not set - Exit code
0for success - Exit code
1for operational failures - Exit code
2for usage or validation errors when the command framework makes that distinction easy
- Config belongs under
~/.config/silentcastle/<tool>/or a single clear file under that path - Cache belongs under
~/.cache/silentcastle/<tool>/ - Environment variables should use stable, tool-specific names
- Document env precedence clearly when flags, config, and env interact
Recommended precedence:
- explicit flags
- environment
- config file
- built-in defaults
If a command intentionally differs, document the reason in code help and docs/<tool>.md.
cmd/<name>/is the default home for code used by only one commandcmd/<name>/internal/is acceptable when a command needs subpackages but the code is still command-local- Root
internal/is for sharable libraries used by multiple commands - Do not move code into root
internal/just because it is large - If a package has only one consumer, keep it with that command unless a second consumer is expected immediately and the reuse boundary is already clear
- Use Bubble Tea v2 for all new TUIs
- Use alt screen only when it materially improves the workflow
- Keep help text visible in the UI for the main keybindings
- Keep data loading and shell-out logic outside the view code
- Prefer a startup validation phase before entering the TUI
- If a TUI also needs non-interactive output, expose that as a normal Kong subcommand or flag-driven mode instead of overloading the TUI path
- If the built-in help is enough,
--helpmay be the only documentation - If a command has workflows, env combinations, auth setup, or multi-step scenarios, add
docs/<tool>.md - Keep the long-form docs plain and example-driven
- New shared logic in root
internal/should be unit-testable - Pure parsing and validation logic should stay outside
main()where practical - TUI-heavy code does not need exhaustive snapshot testing by default, but parsing, config, and state transitions should be testable where it pays off
- New Go commands should start on Kong
- Existing hand-rolled Go CLIs do not need a blind rewrite
- When an existing Go CLI gets meaningful work, migrate it toward this standard unless there is a strong reason not to
ghrelandssm-connectshould stay on Bubble Tea v2; if they gain richer top-level command structure, move their argument parsing to Kong as part of normal maintenance
Non-TUI command shape:
package main
import (
"fmt"
"github.com/alecthomas/kong"
)
type listCmd struct {
JSON bool `help:"Emit JSON."`
}
func (c *listCmd) Run() error {
fmt.Println("implement me")
return nil
}
var cli struct {
Version kong.VersionFlag `help:"Print version."`
List listCmd `cmd:"" help:"List items."`
}
func main() {
ctx := kong.Parse(&cli,
kong.Name("example"),
kong.Description("One-line command summary."),
)
err := ctx.Run()
ctx.FatalIfErrorf(err)
}TUI command shape:
package main
import (
tea "charm.land/bubbletea/v2"
"github.com/alecthomas/kong"
)
var cli struct {
Profile string `help:"AWS profile." env:"AWS_PROFILE"`
NoAlt bool `help:"Run without alternate screen mode."`
}
func main() {
kctx := kong.Parse(&cli,
kong.Name("example-tui"),
kong.Description("Example TUI command."),
)
model, err := newModel(cli.Profile)
kctx.FatalIfErrorf(err)
opts := []tea.ProgramOption{}
if !cli.NoAlt {
opts = append(opts, tea.WithAltScreen())
}
_, err = tea.NewProgram(model, opts...).Run()
kctx.FatalIfErrorf(err)
}