cli-structure
Skill3 starsChanged 8 months agoMITView on GitHub
Go CLI project structure with Cobra and BubbleTea. Use when creating new commands, packages, or modules, organizing project layout, wiring dependencies, setting up Cobra commands, or deciding where code should live. Triggers on new file/package creation, cmd/ changes, internal/ organization, or main.go modifications.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- masonhuemmer/dopsword for word, first seen Mar 24, 2026
Other versions1 project uses a version of this.
Word for word · 1
- masonhuemmer/dops★ 3100% same
Edited · 0
None found.
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository19 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- bubbletea-patternsSkill
- charm-stylingSkill
- clean-code-boundariesSkill
- clean-code-designSkill
- clean-code-errorsSkill
- clean-code-functionsSkill
- clean-code-namingSkill
- clean-code-solidSkill
- clean-code-testingSkill
- create-runbookSkill
- demo-recordingSkill
- mutation-testingSkill
- shell-scriptsSkill
- spec-workflowSkill
- tdd-workflowSkill
- tui-layoutSkill
- tui-testingSkill
- wizard-formsSkill
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 1 is distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 93
Always use RunE (returns error), never Run
- Very specific: line 94
Use Args validators: NoArgs, ExactArgs(n), MinimumNArgs(n), RangeArgs(min, max)
- Distinctive: line 116
Not every command needs a TUI.
- Very specific: line 170
Never import cmd/ from internal/
- Very specific: line 171
Never read environment variables or flags in internal/ — inject values
- Very specific: line 173
Keep cmd/ files focused on wiring — no business logic
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLI Project Structure
This project uses Cobra for CLI routing and BubbleTea v2 for interactive TUI.
Directory Layout
dops/
├── main.go # Minimal — calls cmd.Execute()
├── Makefile # Build, test, lint, screenshots, docker, ci
├── Dockerfile # Multi-stage Alpine build for MCP server
├── .goreleaser.yml # Multi-platform release with Homebrew tap
├── .github/workflows/ # CI: test.yml + release.yml
├── cmd/
│ ├── root.go # Root command, DOPS_HOME env, TUI launch
│ ├── version.go
│ ├── run.go # dops run <id>
│ ├── config.go # dops config set/get/unset/list
│ ├── catalog.go # dops catalog list/add/remove/install/update
│ └── mcp.go # dops mcp serve/tools
├── internal/
│ ├── tui/
│ │ ├── app.go # Root tea.Model — state machine, focus, overlays
│ │ ├── sidebar/ # Catalog tree with search, collapse, scrollbar
│ │ ├── metadata/ # Runbook details, click-to-copy
│ │ ├── output/ # Log pane: scroll, search, text selection
│ │ ├── wizard/ # Custom field-by-field parameter input
│ │ ├── confirm/ # Risk confirmation overlay
│ │ ├── help/ # Context-aware keybinding overlay
│ │ ├── palette/ # Command palette (ctrl+shift+p)
│ │ └── footer/ # Status bar with keybinding hints
│ ├── mcp/ # MCP server: tools, resources, schema, progress
│ ├── domain/ # Core types: Runbook, Config, RiskLevel
│ ├── config/ # Config store, dot-notation path access
│ ├── catalog/ # Catalog loader, disk scanner
│ ├── executor/ # Script runner with io.Pipe streaming
│ ├── vars/ # Variable resolver (global → catalog → runbook)
│ ├── theme/ # JSON theme loader, resolver, styles builder
│ ├── crypto/ # Age encryption/decryption
│ ├── clipboard/ # OSC 52 clipboard fallback
│ └── adapters/ # FileSystem, LogWriter
├── specs/ # Versioned spec (dops-v0.1.0.md)
├── plans/ # Implementation plans (completed/)
├── tapes/ # VHS tapes, screenshots, GIFs
└── LICENSEmain.go
Keep it minimal:
package main
import "dops/cmd"
func main() {
cmd.Execute()
}Cobra Command Pattern
One command per file in cmd/:
package cmd
import "github.com/spf13/cobra"
var deployCmd = &cobra.Command{
Use: "deploy [target]",
Short: "Deploy to a target environment",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
// Wire dependencies, launch TUI or execute
return nil
},
}
func init() {
rootCmd.AddCommand(deployCmd)
deployCmd.Flags().BoolVarP(&dryRun, "dry-run", "n", false, "preview without applying")
}Rules:
- Always use
RunE(returns error), neverRun - Use
Argsvalidators:NoArgs,ExactArgs(n),MinimumNArgs(n),RangeArgs(min, max) - Commands without
RunEact as groups (print help)
Cobra + BubbleTea Handoff
Cobra parses flags and args, then hands off to BubbleTea:
RunE: func(cmd *cobra.Command, args []string) error {
// 1. Resolve config from flags/viper
cfg := resolveConfig(cmd)
// 2. Create TUI model with injected dependencies
model := tui.NewModel(cfg)
// 3. Launch BubbleTea
p := tea.NewProgram(model)
_, err := p.Run()
return err
}Not every command needs a TUI. Simple commands (version, config, completion) use plain stdout.
Flag Handling
Persistent flags (all subcommands):
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file path")
rootCmd.PersistentFlags().CountVarP(&verbosity, "verbose", "v", "verbosity (-v, -vv, -vvv)")Flag groups:
cmd.MarkFlagsRequiredTogether("username", "password")
cmd.MarkFlagsMutuallyExclusive("json", "yaml")
cmd.MarkFlagsOneRequired("json", "yaml")PreRun Hooks
Execution order: PersistentPreRunE → PreRunE → RunE → PostRunE → PersistentPostRunE
var rootCmd = &cobra.Command{
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return initLogging() // runs before ALL commands
},
}Dependency Wiring
Wire dependencies in cmd/ or a dedicated wire.go, NOT in business logic:
// cmd/deploy.go — composition root
RunE: func(cmd *cobra.Command, args []string) error {
store := awsstore.New(cfg.Region) // concrete adapter
deployer := deploy.New(store) // inject interface
return deployer.Run(cmd.Context())
}Business logic in internal/ accepts interfaces, never concrete external types.
Package Boundaries
cmd/— CLI wiring only. Parses flags, creates dependencies, calls business logic.internal/tui/— BubbleTea models, views, styles. Depends on business logic interfaces.internal/<domain>/— Pure business logic. No CLI, no TUI, no external imports.internal/adapters/— Thin wrappers around external services implementing domain interfaces.
Rules
main.godoes one thing: callscmd.Execute()- Never import
cmd/frominternal/ - Never read environment variables or flags in
internal/— inject values - Each subcommand file registers itself via
init()→rootCmd.AddCommand() - Keep
cmd/files focused on wiring — no business logic
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

