Commit 08c012f
Changed files (19)
docs/config.md → docs/cmd/config.md
File renamed without changes
docs/export.md → docs/cmd/export.md
File renamed without changes
docs/import.md → docs/cmd/import.md
File renamed without changes
docs/index.md → docs/cmd/index.md
File renamed without changes
docs/init.md → docs/cmd/init.md
File renamed without changes
docs/list.md → docs/cmd/list.md
File renamed without changes
docs/new.md → docs/cmd/new.md
File renamed without changes
docs/pull-push.md → docs/cmd/pull-push.md
File renamed without changes
docs/search.md → docs/cmd/search.md
File renamed without changes
docs/start.md → docs/cmd/start.md
File renamed without changes
docs/status.md → docs/cmd/status.md
File renamed without changes
docs/update.md → docs/cmd/update.md
File renamed without changes
docs/view.md → docs/cmd/view.md
File renamed without changes
docs/book.toml
@@ -0,0 +1,5 @@
+[book]
+authors = ["bryfry"]
+language = "en"
+src = "."
+title = "tissue"
docs/cobra-cli.md
@@ -0,0 +1,83 @@
+# Functional Cobra CLI Pattern
+
+This document describes a functional approach to structuring Cobra CLI applications that avoids global variables and init functions in favor of explicit, testable code.
+
+## Key Principles
+
+1. **No Global Variables**: All command state is encapsulated within functions
+2. **No Init Functions**: Explicit initialization through constructor functions
+3. **Clear Control Flow**: Easy to follow execution path from main() through command execution
+4. **Testability**: Each command can be instantiated and tested in isolation
+5. **Composable**: Each cobra.Command could be the root of it's own cli, the root of this cli could be a subcommand of another cli application.
+
+## Project Structure
+
+```
+.
+├── main.go # Entry point - minimal, just calls Execute()
+└── cmd/
+ ├── root.go # Root command and Execute() function
+ ├── init.go # Example subcommand
+ └── ... # Additional subcommands
+```
+
+## Implementation Pattern
+
+### cmd/root.go
+Root command constructor:
+
+```go
+// New command sets up a Command and registers subcommands directly
+func NewRootCmd() *cobra.Command {
+ var cmd = &cobra.Command{
+ RunE: rootRunE, // Always RunE
+ // ...
+ }
+
+ // Add subcommands
+ cmd.AddCommand(NewOtherCmd())
+
+ return cmd
+}
+
+// rootRunE is the run function for the root command
+func rootRunE(cmd *cobra.Command, args []string) error { ... }
+```
+
+### cmd/subcommand.go
+Pattern for subcommands:
+
+```go
+// New command sets up a sub command the same way
+func NewSubCmd() *cobra.Command {
+ var cmd = &cobra.Command{
+ RunE: subRunE, // Always RunE
+ }
+ // ...
+ return cmd
+}
+
+// subCmdRunE is the run function for the subcommand
+func subRunE(cmd *cobra.Command, args []string) error { ... }
+```
+
+## Advantages Over Standard Cobra Template
+
+### 1. No Global State
+The standard template often uses global variables for flags and configuration.
+Our pattern encapsulates everything in functions.
+
+### 2. Explicit Initialization
+No hidden init() functions that run automatically. Everything is explicitly called:
+- `main()` calls `cmd.Execute()`
+- `Execute()` calls `NewRootCmd()`
+- `NewRootCmd()` explicitly adds subcommands
+
+### 3. Better Testing
+Each command can be instantiated independently for testing:
+```go
+func TestInitCommand(t *testing.T) {
+ cmd := NewInitCmd()
+ // Test the command in isolation
+}
+```
docs/README.md
@@ -0,0 +1,1 @@
+../README.md
\ No newline at end of file
docs/SUMMARY.md
@@ -0,0 +1,26 @@
+# Summary
+
+[Introduction](README.md)
+
+# User Guide
+
+- [Functional Cobra CLI Pattern](cobra-cli.md)
+
+# Commands
+
+- [init](cmd/init.md)
+- [new](cmd/new.md)
+- [list](cmd/list.md)
+- [view](cmd/view.md)
+- [update](cmd/update.md)
+- [start](cmd/start.md)
+- [status](cmd/status.md)
+- [search](cmd/search.md)
+- [index](cmd/index.md)
+- [config](cmd/config.md)
+
+# Synchronization
+
+- [pull & push](cmd/pull-push.md)
+- [import](cmd/import.md)
+- [export](cmd/export.md)
.gitignore
@@ -0,0 +1,1 @@
+docs/book
README.md
@@ -12,9 +12,9 @@ Tissue is a command-line tool designed to manage issue tracking directly within
- **Issues as Markdown**: Each issue is a Markdown file with front matter (like YAML) for metadata and a body for the description.
-- **Dedicated Branch**: All issues live in a single "tissues" branch, which acts as the single source of truth for issue tracking.
+- **Dedicated Branch**: All issues live in a single "issues" branch, which acts as the single source of truth for issue tracking.
-- **Worktree Integration**: The "tissues" branch can be managed via a Git worktree, ensuring the issues directory is always synced and easily accessible.
+- **Worktree Integration**: The "issues" branch can be managed via a Git worktree, ensuring the issues directory is always synced and easily accessible.
## Implementation Details
@@ -23,14 +23,20 @@ Tissue is a command-line tool designed to manage issue tracking directly within
- **CLI Commands**: Tissue provides commands to list issues, sort them by category or status, and generate an index file (like a README) summarizing current issues.
-- **Editing and Updates**: When editing issues, the CLI can use the worktree to ensure the user is always working off the latest "tissues" branch version. Direct edits are made there and then merged as needed.
+- **Editing and Updates**: When editing issues, the CLI can use the worktree to ensure the user is always working off the latest "issues" branch version. Direct edits are made there and then merged as needed.
## Collaboration
-- **Multiple Users**: Multiple people can work on the "tissues" branch, and normal Git merge conflict resolution applies if more than one person edits the same issue file.
+- **Multiple Users**: Multiple people can work on the "issues" branch, and normal Git merge conflict resolution applies if more than one person edits the same issue file.
+## Documentation
+
+```bash
+mdbook serve docs
+```
+
## Usage Examples
### Initial Setup